aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-05-19 17:10:40 -0700
committerJoel Galenson <jgalenson@google.com>2021-05-19 17:10:40 -0700
commit308069c5374db331b47e645d2b0c97f19bc7caad (patch)
tree2d40aeccbf398a4c84a3ee38303459327f8d0427 /src
parentd015e3b2531f9a3fcf4f46d82d9525c56a52186b (diff)
downloadserde_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.rs4
-rw-r--r--src/lib.rs2
-rw-r--r--src/map.rs34
-rw-r--r--src/read.rs10
4 files changed, 45 insertions, 5 deletions
diff --git a/src/de.rs b/src/de.rs
index 4abe7ef..15c8236 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -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();
diff --git a/src/lib.rs b/src/lib.rs
index c3766b5..1d75083 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(
diff --git a/src/map.rs b/src/map.rs
index f09d840..b564446 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -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),
})