diff options
author | Chih-Hung Hsieh <chh@google.com> | 2020-10-26 13:16:59 -0700 |
---|---|---|
committer | Chih-Hung Hsieh <chh@google.com> | 2020-10-26 13:16:59 -0700 |
commit | b93bfcba9d36ec61a226fcdc1c165e1b6059389e (patch) | |
tree | 11096d189d927284080711588bbdbf8aabac0828 /src | |
parent | aa0f7330b237467bcfb52c24f9c1e11a4645db4b (diff) | |
download | serde_json-b93bfcba9d36ec61a226fcdc1c165e1b6059389e.tar.gz |
Upgrade rust/crates/serde_json to 1.0.59
Test: make
Change-Id: I4bea1b55837c5667419f03ff562973006381e613
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/map.rs | 50 | ||||
-rw-r--r-- | src/number.rs | 2 |
3 files changed, 53 insertions, 3 deletions
@@ -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.57")] +#![doc(html_root_url = "https://docs.rs/serde_json/1.0.59")] #![deny(clippy::all, clippy::pedantic)] // Ignored clippy lints #![allow( @@ -329,6 +329,7 @@ clippy::enum_glob_use, clippy::if_not_else, clippy::integer_division, + clippy::map_err_ignore, clippy::match_same_arms, clippy::similar_names, clippy::unused_self, @@ -378,6 +379,7 @@ mod lib { pub use self::core::hash::{self, Hash}; pub use self::core::iter::FusedIterator; pub use self::core::marker::{self, PhantomData}; + pub use self::core::ops::{Bound, RangeBounds}; pub use self::core::result::{self, Result}; pub use self::core::{borrow, char, cmp, iter, mem, num, ops, slice, str}; @@ -122,11 +122,59 @@ impl Map<String, Value> { return self.map.remove(key); } + /// Removes a key from the map, returning the stored key and value if the + /// key was previously in the map. + /// + /// The key may be any borrowed form of the map's key type, but the ordering + /// on the borrowed form *must* match the ordering on the key type. + pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)> + where + String: Borrow<Q>, + Q: ?Sized + Ord + Eq + Hash, + { + #[cfg(any(feature = "preserve_order", not(no_btreemap_remove_entry)))] + return self.map.remove_entry(key); + #[cfg(all( + not(feature = "preserve_order"), + no_btreemap_remove_entry, + not(no_btreemap_get_key_value), + ))] + { + let (key, _value) = self.map.get_key_value(key)?; + let key = key.clone(); + let value = self.map.remove::<String>(&key)?; + Some((key, value)) + } + #[cfg(all( + not(feature = "preserve_order"), + no_btreemap_remove_entry, + no_btreemap_get_key_value, + ))] + { + struct Key<'a, Q: ?Sized>(&'a Q); + + impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> { + fn start_bound(&self) -> Bound<&Q> { + Bound::Included(self.0) + } + fn end_bound(&self) -> Bound<&Q> { + Bound::Included(self.0) + } + } + + let mut range = self.map.range(Key(key)); + let (key, _value) = range.next()?; + let key = key.clone(); + let value = self.map.remove::<String>(&key)?; + Some((key, value)) + } + } + /// Moves all elements from other into Self, leaving other empty. #[inline] pub fn append(&mut self, other: &mut Self) { #[cfg(feature = "preserve_order")] - for (k, v) in std::mem::replace(&mut other.map, MapImpl::default()) { + for (k, v) in mem::replace(&mut other.map, MapImpl::default()) { self.map.insert(k, v); } #[cfg(not(feature = "preserve_order"))] diff --git a/src/number.rs b/src/number.rs index 04a5602..c147618 100644 --- a/src/number.rs +++ b/src/number.rs @@ -211,7 +211,7 @@ impl Number { N::Float(n) => Some(n), } #[cfg(feature = "arbitrary_precision")] - self.n.parse().ok() + self.n.parse::<f64>().ok().filter(|float| float.is_finite()) } /// Converts a finite `f64` to a `Number`. Infinite or NaN values are not JSON |