diff options
author | Joel Galenson <jgalenson@google.com> | 2021-08-09 10:42:14 -0700 |
---|---|---|
committer | Joel Galenson <jgalenson@google.com> | 2021-08-09 10:42:14 -0700 |
commit | d1eaeafe62d863e70b0799b9abb03fc744916f3f (patch) | |
tree | f57d25447b80ff53d9487d7c1ac72bb9c4dad1d6 | |
parent | 3115b28ef9235e9402d5cb418eeb0dd2ffe91d2f (diff) | |
download | serde_json-d1eaeafe62d863e70b0799b9abb03fc744916f3f.tar.gz |
Upgrade rust/crates/serde_json to 1.0.66
Test: make
Change-Id: I100c880dcc908b9d74aacbf8c3619099a30d8aba
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 8 | ||||
-rw-r--r-- | Cargo.toml | 12 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | src/de.rs | 11 | ||||
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/iter.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/map.rs | 2 | ||||
-rw-r--r-- | src/raw.rs | 2 | ||||
-rw-r--r-- | src/read.rs | 5 | ||||
-rw-r--r-- | src/ser.rs | 27 | ||||
-rw-r--r-- | src/value/mod.rs | 53 |
15 files changed, 77 insertions, 88 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index dd6bf24..53f9a19 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "d0d80783d31161c869922fad933b3623715506d2" + "sha1": "6346bb30037f31ea69b9a4eb029875e23521681c" } } @@ -62,10 +62,10 @@ rust_library { // dependent_library ["feature_list"] // itoa-0.4.7 -// proc-macro2-1.0.26 "default,proc-macro" +// proc-macro2-1.0.28 "default,proc-macro" // quote-1.0.9 "default,proc-macro" // ryu-1.0.5 -// serde-1.0.126 "default,derive,serde_derive,std" -// serde_derive-1.0.126 "default" -// syn-1.0.72 "clone-impls,default,derive,parsing,printing,proc-macro,quote" +// serde-1.0.127 "default,derive,serde_derive,std" +// serde_derive-1.0.127 "default" +// syn-1.0.74 "clone-impls,default,derive,parsing,printing,proc-macro,quote" // unicode-xid-0.2.2 "default" @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "serde_json" -version = "1.0.64" +version = "1.0.66" authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] include = ["build.rs", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] description = "A JSON serialization file format" @@ -25,6 +24,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/serde-rs/json" [package.metadata.docs.rs] features = ["raw_value", "unbounded_depth"] +rustdoc-args = ["--cfg", "docsrs"] targets = ["x86_64-unknown-linux-gnu"] [package.metadata.playground] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 6ecb159..a664e75 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "serde_json" -version = "1.0.64" # remember to update html_root_url +version = "1.0.66" # remember to update html_root_url authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>", "David Tolnay <dtolnay@gmail.com>"] license = "MIT OR Apache-2.0" description = "A JSON serialization file format" @@ -32,6 +32,7 @@ members = ["tests/crate"] [package.metadata.docs.rs] features = ["raw_value", "unbounded_depth"] targets = ["x86_64-unknown-linux-gnu"] +rustdoc-args = ["--cfg", "docsrs"] [package.metadata.playground] features = ["raw_value"] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/serde_json/serde_json-1.0.64.crate" + value: "https://static.crates.io/crates/serde_json/serde_json-1.0.66.crate" } - version: "1.0.64" + version: "1.0.66" license_type: NOTICE last_upgrade_date { year: 2021 - month: 5 - day: 19 + month: 8 + day: 9 } } @@ -81,9 +81,11 @@ A string of JSON data can be parsed into a `serde_json::Value` by the [`from_reader`][from_reader] for parsing from any `io::Read` like a File or a TCP stream. +<div align="right"> <a href="https://play.rust-lang.org/?edition=2018&gist=d69d8e3156d4bb81c4461b60b772ab72" target="_blank"> -<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png"> +<img align="center" width="85" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png"> </a> +</div> ```rust use serde_json::{Result, Value}; @@ -139,9 +141,11 @@ in one of the dozens of places it is used in your code. Serde provides a powerful way of mapping JSON data into Rust data structures largely automatically. +<div align="right"> <a href="https://play.rust-lang.org/?edition=2018&gist=15cfab66d38ff8a15a9cf1d8d897ac68" target="_blank"> -<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png"> +<img align="center" width="85" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png"> </a> +</div> ```rust use serde::{Deserialize, Serialize}; @@ -206,9 +210,11 @@ derive]* page of the Serde site. Serde JSON provides a [`json!` macro][macro] to build `serde_json::Value` objects with very natural JSON syntax. +<div align="right"> <a href="https://play.rust-lang.org/?edition=2018&gist=6ccafad431d72b62e77cc34c8e879b24" target="_blank"> -<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png"> +<img align="center" width="85" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png"> </a> +</div> ```rust use serde_json::json; @@ -239,9 +245,11 @@ be interpolated directly into the JSON value as you are building it. Serde will check at compile time that the value you are interpolating is able to be represented as JSON. +<div align="right"> <a href="https://play.rust-lang.org/?edition=2018&gist=f9101a6e61dfc9e02c6a67f315ed24f2" target="_blank"> -<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png"> +<img align="center" width="85" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png"> </a> +</div> ```rust let full_name = "John Doe"; @@ -270,9 +278,11 @@ A data structure can be converted to a JSON string by [`serde_json::to_writer`][to_writer] which serializes to any `io::Write` such as a File or a TCP stream. +<div align="right"> <a href="https://play.rust-lang.org/?edition=2018&gist=3472242a08ed2ff88a944f2a2283b0ee" target="_blank"> -<img align="right" width="50" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/run.png"> +<img align="center" width="85" src="https://raw.githubusercontent.com/serde-rs/serde-rs.github.io/master/img/runtab.png"> </a> +</div> ```rust use serde::{Deserialize, Serialize}; @@ -350,7 +360,7 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } For JSON support in Serde without a memory allocator, please see the [`serde-json-core`] crate. -[`serde-json-core`]: https://japaric.github.io/serde-json-core/serde_json_core/ +[`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core [value]: https://docs.serde.rs/serde_json/value/enum.Value.html [from_str]: https://docs.serde.rs/serde_json/de/fn.from_str.html @@ -196,6 +196,7 @@ impl<'de, R: Read<'de>> Deserializer<R> { /// } /// ``` #[cfg(feature = "unbounded_depth")] + #[cfg_attr(docsrs, doc(cfg(feature = "unbounded_depth")))] pub fn disable_recursion_limit(&mut self) { self.disable_recursion_limit = true; } @@ -898,7 +899,7 @@ impl<'de, R: Read<'de>> Deserializer<R> { fn scan_number(&mut self, buf: &mut String) -> Result<()> { match tri!(self.peek_or_null()) { b'.' => self.scan_decimal(buf), - b'e' | b'E' => self.scan_exponent(buf), + e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf), _ => Ok(()), } } @@ -923,19 +924,20 @@ impl<'de, R: Read<'de>> Deserializer<R> { } match tri!(self.peek_or_null()) { - b'e' | b'E' => self.scan_exponent(buf), + e @ b'e' | e @ b'E' => self.scan_exponent(e as char, buf), _ => Ok(()), } } #[cfg(feature = "arbitrary_precision")] - fn scan_exponent(&mut self, buf: &mut String) -> Result<()> { + fn scan_exponent(&mut self, e: char, buf: &mut String) -> Result<()> { self.eat_char(); - buf.push('e'); + buf.push(e); match tri!(self.peek_or_null()) { b'+' => { self.eat_char(); + buf.push('+'); } b'-' => { self.eat_char(); @@ -2494,6 +2496,7 @@ where /// the JSON map or some number is too big to fit in the expected primitive /// type. #[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn from_reader<R, T>(rdr: R) -> Result<T> where R: crate::io::Read, diff --git a/src/error.rs b/src/error.rs index 7dcdd81..4219d32 100644 --- a/src/error.rs +++ b/src/error.rs @@ -234,7 +234,7 @@ pub(crate) enum ErrorCode { /// JSON has non-whitespace trailing characters after the value. TrailingCharacters, - /// Unexpected end of hex excape. + /// Unexpected end of hex escape. UnexpectedEndOfHexEscape, /// Encountered nesting of JSON maps and arrays more than 128 layers deep. diff --git a/src/iter.rs b/src/iter.rs index c14026f..9792916 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -12,7 +12,7 @@ pub struct LineColIterator<I> { /// The column is 0 immediately after a newline character has been read. col: usize, - /// Byte offset of the start of the current line. This is the sum of lenghts + /// Byte offset of the start of the current line. This is the sum of lengths /// of all previous lines. Keeping track of things this way allows efficient /// computation of the current line, column, and byte offset while only /// updating one of the counters in `next()` in the common case. @@ -298,9 +298,9 @@ //! [to_vec]: https://docs.serde.rs/serde_json/ser/fn.to_vec.html //! [to_writer]: https://docs.serde.rs/serde_json/ser/fn.to_writer.html //! [macro]: https://docs.serde.rs/serde_json/macro.json.html -//! [`serde-json-core`]: https://japaric.github.io/serde-json-core/serde_json_core/ +//! [`serde-json-core`]: https://github.com/rust-embedded-community/serde-json-core -#![doc(html_root_url = "https://docs.rs/serde_json/1.0.64")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.66")] #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints #![allow( @@ -357,6 +357,7 @@ #![allow(non_upper_case_globals)] #![deny(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(docsrs, feature(doc_cfg))] //////////////////////////////////////////////////////////////////////////////// @@ -453,6 +454,7 @@ pub mod de; pub mod error; pub mod map; #[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub mod ser; #[cfg(not(feature = "std"))] mod ser; @@ -52,7 +52,7 @@ impl Map<String, Value> { /// Clears the map, removing all values. #[inline] pub fn clear(&mut self) { - self.map.clear() + self.map.clear(); } /// Returns a reference to the value corresponding to the key. @@ -109,6 +109,7 @@ use serde::ser::{Serialize, SerializeStruct, Serializer}; /// } /// ``` #[repr(C)] +#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))] pub struct RawValue { json: str, } @@ -267,6 +268,7 @@ impl RawValue { /// /// println!("{}", serde_json::value::to_raw_value(&map).unwrap_err()); /// ``` +#[cfg_attr(docsrs, doc(cfg(feature = "raw_value")))] pub fn to_raw_value<T>(value: &T) -> Result<Box<RawValue>, Error> where T: Serialize, diff --git a/src/read.rs b/src/read.rs index d247c30..8ed3d7d 100644 --- a/src/read.rs +++ b/src/read.rs @@ -140,6 +140,7 @@ where /// JSON input source that reads from a std::io input stream. #[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub struct IoRead<R> where R: io::Read, @@ -716,7 +717,7 @@ where } fn discard(&mut self) { - R::discard(self) + R::discard(self); } fn position(&self) -> Position { @@ -766,7 +767,7 @@ where const should_early_return_if_failed: bool = R::should_early_return_if_failed; fn set_failed(&mut self, failed: &mut bool) { - R::set_failed(self, failed) + R::set_failed(self, failed); } } @@ -8,6 +8,7 @@ use serde::ser::{self, Impossible, Serialize}; use serde::serde_if_integer128; /// A structure for serializing Rust values into JSON. +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub struct Serializer<W, F = CompactFormatter> { writer: W, formatter: F, @@ -316,13 +317,13 @@ where #[inline] fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq> { + tri!(self + .formatter + .begin_array(&mut self.writer) + .map_err(Error::io)); if len == Some(0) { tri!(self .formatter - .begin_array(&mut self.writer) - .map_err(Error::io)); - tri!(self - .formatter .end_array(&mut self.writer) .map_err(Error::io)); Ok(Compound::Map { @@ -330,10 +331,6 @@ where state: State::Empty, }) } else { - tri!(self - .formatter - .begin_array(&mut self.writer) - .map_err(Error::io)); Ok(Compound::Map { ser: self, state: State::First, @@ -385,13 +382,13 @@ where #[inline] fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap> { + tri!(self + .formatter + .begin_object(&mut self.writer) + .map_err(Error::io)); if len == Some(0) { tri!(self .formatter - .begin_object(&mut self.writer) - .map_err(Error::io)); - tri!(self - .formatter .end_object(&mut self.writer) .map_err(Error::io)); Ok(Compound::Map { @@ -399,10 +396,6 @@ where state: State::Empty, }) } else { - tri!(self - .formatter - .begin_object(&mut self.writer) - .map_err(Error::io)); Ok(Compound::Map { ser: self, state: State::First, @@ -2149,6 +2142,7 @@ static ESCAPE: [u8; 256] = [ /// Serialization can fail if `T`'s implementation of `Serialize` decides to /// fail, or if `T` contains a map with non-string keys. #[inline] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn to_writer<W, T>(writer: W, value: &T) -> Result<()> where W: io::Write, @@ -2167,6 +2161,7 @@ where /// Serialization can fail if `T`'s implementation of `Serialize` decides to /// fail, or if `T` contains a map with non-string keys. #[inline] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn to_writer_pretty<W, T>(writer: W, value: &T) -> Result<()> where W: io::Write, diff --git a/src/value/mod.rs b/src/value/mod.rs index 88d2ef6..a28da66 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -758,25 +758,15 @@ impl Value { if !pointer.starts_with('/') { return None; } - let tokens = pointer + pointer .split('/') .skip(1) - .map(|x| x.replace("~1", "/").replace("~0", "~")); - let mut target = self; - - for token in tokens { - let target_opt = match *target { - Value::Object(ref map) => map.get(&token), - Value::Array(ref list) => parse_index(&token).and_then(|x| list.get(x)), - _ => return None, - }; - if let Some(t) = target_opt { - target = t; - } else { - return None; - } - } - Some(target) + .map(|x| x.replace("~1", "/").replace("~0", "~")) + .try_fold(self, |target, token| match target { + Value::Object(map) => map.get(&token), + Value::Array(list) => parse_index(&token).and_then(|x| list.get(x)), + _ => None, + }) } /// Looks up a value by a JSON Pointer and returns a mutable reference to @@ -823,30 +813,15 @@ impl Value { if !pointer.starts_with('/') { return None; } - let tokens = pointer + pointer .split('/') .skip(1) - .map(|x| x.replace("~1", "/").replace("~0", "~")); - let mut target = self; - - for token in tokens { - // borrow checker gets confused about `target` being mutably borrowed too many times because of the loop - // this once-per-loop binding makes the scope clearer and circumvents the error - let target_once = target; - let target_opt = match *target_once { - Value::Object(ref mut map) => map.get_mut(&token), - Value::Array(ref mut list) => { - parse_index(&token).and_then(move |x| list.get_mut(x)) - } - _ => return None, - }; - if let Some(t) = target_opt { - target = t; - } else { - return None; - } - } - Some(target) + .map(|x| x.replace("~1", "/").replace("~0", "~")) + .try_fold(self, |target, token| match target { + Value::Object(map) => map.get_mut(&token), + Value::Array(list) => parse_index(&token).and_then(move |x| list.get_mut(x)), + _ => None, + }) } /// Takes the value out of the `Value`, leaving a `Null` in its place. |