diff options
author | Joel Galenson <jgalenson@google.com> | 2021-05-19 17:10:40 -0700 |
---|---|---|
committer | Joel Galenson <jgalenson@google.com> | 2021-05-19 17:10:40 -0700 |
commit | 308069c5374db331b47e645d2b0c97f19bc7caad (patch) | |
tree | 2d40aeccbf398a4c84a3ee38303459327f8d0427 /src | |
parent | d015e3b2531f9a3fcf4f46d82d9525c56a52186b (diff) | |
download | serde_json-308069c5374db331b47e645d2b0c97f19bc7caad.tar.gz |
Upgrade rust/crates/serde_json to 1.0.64
Test: make
Change-Id: I058d09e243a200353f09f6fcb22a185b9c10df75
Diffstat (limited to 'src')
-rw-r--r-- | src/de.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/map.rs | 34 | ||||
-rw-r--r-- | src/read.rs | 10 |
4 files changed, 45 insertions, 5 deletions
@@ -41,7 +41,7 @@ where /// Typically it is more convenient to use one of these methods instead: /// /// - Deserializer::from_str - /// - Deserializer::from_bytes + /// - Deserializer::from_slice /// - Deserializer::from_reader pub fn new(read: R) -> Self { Deserializer { @@ -2250,7 +2250,7 @@ where /// Typically it is more convenient to use one of these methods instead: /// /// - Deserializer::from_str(...).into_iter() - /// - Deserializer::from_bytes(...).into_iter() + /// - Deserializer::from_slice(...).into_iter() /// - Deserializer::from_reader(...).into_iter() pub fn new(read: R) -> Self { let offset = read.byte_offset(); @@ -300,7 +300,7 @@ //! [macro]: https://docs.serde.rs/serde_json/macro.json.html //! [`serde-json-core`]: https://japaric.github.io/serde-json-core/serde_json_core/ -#![doc(html_root_url = "https://docs.rs/serde_json/1.0.62")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.64")] #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints #![allow( @@ -542,6 +542,40 @@ impl<'a> Entry<'a> { Entry::Occupied(entry) => entry.into_mut(), } } + + /// Provides in-place mutable access to an occupied entry before any + /// potential inserts into the map. + /// + /// # Examples + /// + /// ``` + /// # use serde_json::json; + /// # + /// let mut map = serde_json::Map::new(); + /// map.entry("serde") + /// .and_modify(|e| *e = json!("rust")) + /// .or_insert(json!("cpp")); + /// + /// assert_eq!(map["serde"], "cpp"); + /// + /// map.entry("serde") + /// .and_modify(|e| *e = json!("rust")) + /// .or_insert(json!("cpp")); + /// + /// assert_eq!(map["serde"], "rust"); + /// ``` + pub fn and_modify<F>(self, f: F) -> Self + where + F: FnOnce(&mut Value), + { + match self { + Entry::Occupied(mut entry) => { + f(entry.get_mut()); + Entry::Occupied(entry) + } + Entry::Vacant(entry) => Entry::Vacant(entry), + } + } } impl<'a> VacantEntry<'a> { diff --git a/src/read.rs b/src/read.rs index 522c0e0..d247c30 100644 --- a/src/read.rs +++ b/src/read.rs @@ -377,7 +377,10 @@ where V: Visitor<'de>, { let raw = self.raw_buffer.take().unwrap(); - let raw = String::from_utf8(raw).unwrap(); + let raw = match String::from_utf8(raw) { + Ok(raw) => raw, + Err(_) => return error(self, ErrorCode::InvalidUnicodeCodePoint), + }; visitor.visit_map(OwnedRawDeserializer { raw_value: Some(raw), }) @@ -587,7 +590,10 @@ impl<'a> Read<'a> for SliceRead<'a> { V: Visitor<'a>, { let raw = &self.slice[self.raw_buffering_start_index..self.index]; - let raw = str::from_utf8(raw).unwrap(); + let raw = match str::from_utf8(raw) { + Ok(raw) => raw, + Err(_) => return error(self, ErrorCode::InvalidUnicodeCodePoint), + }; visitor.visit_map(BorrowedRawDeserializer { raw_value: Some(raw), }) |