nushell/crates/nu-json
nibon7 69bf43ef56
Apply nightly clippy fixes (#9482)
<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
This PR fixes the following nightly clippy warnings.

```
warning: you should consider adding a `Default` implementation for `HjsonFormatter<'a>`
   --> crates/nu-json/src/ser.rs:700:5
    |
700 | /     pub fn new() -> Self {
701 | |         HjsonFormatter::with_indent(b"  ")
702 | |     }
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
    = note: `#[warn(clippy::new_without_default)]` on by default
help: try adding this
    |
698 + impl<'a> Default for HjsonFormatter<'a> {
699 +     fn default() -> Self {
700 +         Self::new()
701 +     }
702 + }
    |

warning: `nu-json` (lib) generated 1 warning
warning: private item shadows public glob re-export
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   |
note: the name `str_` in the type namespace is supposed to be publicly re-exported here
  --> crates/nu-command/src/strings/mod.rs:17:9
   |
17 | pub use str_::*;
   |         ^^^^^^^
note: but the private item here shadows it
  --> crates/nu-command/src/strings/mod.rs:8:1
   |
8  | mod str_;
   | ^^^^^^^^^
   = note: `#[warn(hidden_glob_reexports)]` on by default

warning: incorrect NaN comparison, NaN cannot be directly compared to itself
   --> crates/nu-command/src/formats/to/nuon.rs:186:20
    |
186 |                 && val != &f64::NAN
    |                    ^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(invalid_nan_comparisons)]` on by default
help: use `f32::is_nan()` or `f64::is_nan()` instead
    |
186 -                 && val != &f64::NAN
186 +                 && !val.is_nan()
    |

warning: `nu-command` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p nu-command` to apply 1 suggestion)
   Compiling nu v0.81.1 (/data/source/nushell)
warning: this expression creates a reference which is immediately dereferenced by the compiler
   --> crates/nu-command/tests/commands/rm.rs:392:27
    |
392 |             dir_to_clean: &test_dir,
    |                           ^^^^^^^^^ help: change this to: `test_dir`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
    = note: `#[warn(clippy::needless_borrow)]` on by default

warning: `nu-command` (test "main") generated 1 warning (run `cargo clippy --fix --test "main"` to apply 1 suggestion)
warning: `nu-command` (lib test) generated 2 warnings (2 duplicates)
warning: `nu-json` (lib test) generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 3.89s

```

# User-Facing Changes
N/A

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
2023-06-20 10:17:33 +02:00
..
src Apply nightly clippy fixes (#9482) 2023-06-20 10:17:33 +02:00
tests replace the regex crate with the fancy-regex crate (#6227) 2022-08-04 14:51:02 -05:00
Cargo.toml Bump to 0.81.1 as development version (#9379) 2023-06-07 15:06:42 +02:00
CHANGELOG.md README for nu-json. Related to nushell/nushell#8253 (#8289) 2023-03-03 19:07:25 -06:00
LICENSE Fix rest of license year ranges (#8727) 2023-04-04 09:03:29 +12:00
README.md README for nu-json. Related to nushell/nushell#8253 (#8289) 2023-03-03 19:07:25 -06:00

nu-json

crate

a fork of serde_hjson.

The changes made to this crate are kept in CHANGELOG.

The Rust implementation of Hjson is based on the Serde JSON Serialization Library.

This crate is a Rust library for parsing and generating Human JSON Hjson. It is built upon Serde, a high performance generic serialization framework.

Install

This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

[dependencies]
serde = "1"
nu-json = "0.76"

From the Commandline

Add with:

 cargo add serde
 cargo add nu-json

Usage

extern crate serde;
extern crate nu_json;

use nu_json::{Map,Value};

fn main() {

    // Now let's look at decoding Hjson data

    let sample_text=r#"
    {
        # specify rate in requests/second
        rate: 1000
        array:
        [
            foo
            bar
        ]
    }"#;

    // Decode and unwrap.
    let mut sample: Map<String, Value> = nu_json::from_str(&sample_text).unwrap();

    // scope to control lifetime of borrow
    {
        // Extract the rate
        let rate = sample.get("rate").unwrap().as_f64().unwrap();
        println!("rate: {}", rate);

        // Extract the array
        let array : &mut Vec<Value> = sample.get_mut("array").unwrap().as_array_mut().unwrap();
        println!("first: {}", array.get(0).unwrap());

        // Add a value
        array.push(Value::String("tak".to_string()));
    }

    // Encode to Hjson
    let sample2 = nu_json::to_string(&sample).unwrap();
    println!("Hjson:\n{}", sample2);
}

DOCS

At the moment, the documentation on serde_hjson / serde_json is also relevant for nu-json.