Struct Map

struct Map<K, V> { ... }

Represents a JSON key/value type.

Implementations

impl Map<alloc::string::String, crate::value::Value>

fn new() -> Self

Makes a new empty Map.

fn with_capacity(capacity: usize) -> Self

Makes a new empty Map with the given initial capacity.

fn clear(self: &mut Self)

Clears the map, removing all values.

fn get<Q>(self: &Self, key: &Q) -> Option<&Value>
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

Returns a reference to the value corresponding to the key.

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.

fn contains_key<Q>(self: &Self, key: &Q) -> bool
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

Returns true if the map contains a value for the specified key.

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.

fn get_mut<Q>(self: &mut Self, key: &Q) -> Option<&mut Value>
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

Returns a mutable reference to the value corresponding to the key.

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.

fn get_key_value<Q>(self: &Self, key: &Q) -> Option<(&String, &Value)>
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

Returns the key-value pair matching the given key.

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.

fn insert(self: &mut Self, k: String, v: Value) -> Option<Value>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

fn remove<Q>(self: &mut Self, key: &Q) -> Option<Value>
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

Removes a key from the map, returning the value at the key 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.

If serde_json's "preserve_order" is enabled, .remove(key) is equivalent to [.swap_remove(key)][Self::swap_remove], replacing this entry's position with the last element. If you need to preserve the relative order of the keys in the map, use [.shift_remove(key)][Self::shift_remove] instead.

fn remove_entry<Q>(self: &mut Self, key: &Q) -> Option<(String, Value)>
where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

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.

If serde_json's "preserve_order" is enabled, .remove_entry(key) is equivalent to [.swap_remove_entry(key)][Self::swap_remove_entry], replacing this entry's position with the last element. If you need to preserve the relative order of the keys in the map, use [.shift_remove_entry(key)][Self::shift_remove_entry] instead.

fn append(self: &mut Self, other: &mut Self)

Moves all elements from other into self, leaving other empty.

fn entry<S>(self: &mut Self, key: S) -> Entry<'_>
where
    S: Into<String>

Gets the given key's corresponding entry in the map for in-place manipulation.

fn len(self: &Self) -> usize

Returns the number of elements in the map.

fn is_empty(self: &Self) -> bool

Returns true if the map contains no elements.

fn iter(self: &Self) -> Iter<'_>

Gets an iterator over the entries of the map.

fn iter_mut(self: &mut Self) -> IterMut<'_>

Gets a mutable iterator over the entries of the map.

fn keys(self: &Self) -> Keys<'_>

Gets an iterator over the keys of the map.

fn values(self: &Self) -> Values<'_>

Gets an iterator over the values of the map.

fn values_mut(self: &mut Self) -> ValuesMut<'_>

Gets an iterator over mutable values of the map.

fn into_values(self: Self) -> IntoValues

Gets an iterator over the values of the map.

fn retain<F>(self: &mut Self, f: F)
where
    F: FnMut(&String, &mut Value) -> bool

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k, &mut v) returns false.

fn sort_keys(self: &mut Self)

Sorts this map's entries in-place using str's usual ordering.

If serde_json's "preserve_order" feature is not enabled, this method does no work because all JSON maps are always kept in a sorted state.

If serde_json's "preserve_order" feature is enabled, this method destroys the original source order or insertion order of this map in favor of an alphanumerical order that matches how a BTreeMap with the same contents would be ordered. This takes O(n log n + c) time where n is the length of the map and c is the capacity.

Other maps nested within the values of this map are not sorted. If you need the entire data structure to be sorted at all levels, you must also call map.values_mut().for_each([Value::sort_all_objects]).

impl Clone for Map<alloc::string::String, crate::value::Value>

fn clone(self: &Self) -> Self
fn clone_from(self: &mut Self, source: &Self)

impl Debug for Map<alloc::string::String, crate::value::Value>

fn fmt(self: &Self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error>

impl Default for Map<alloc::string::String, crate::value::Value>

fn default() -> Self

impl Eq for Map<alloc::string::String, crate::value::Value>

impl Extend for Map<alloc::string::String, crate::value::Value>

fn extend<T>(self: &mut Self, iter: T)
where
    T: IntoIterator<Item = (String, Value)>

impl FromIterator for Map<alloc::string::String, crate::value::Value>

fn from_iter<T>(iter: T) -> Self
where
    T: IntoIterator<Item = (String, Value)>

impl Hash for Map<alloc::string::String, crate::value::Value>

fn hash<H: Hasher>(self: &Self, state: &mut H)

impl IntoIterator for Map<alloc::string::String, crate::value::Value>

fn into_iter(self: Self) -> <Self as >::IntoIter

impl PartialEq for Map<alloc::string::String, crate::value::Value>

fn eq(self: &Self, other: &Self) -> bool

impl Serialize for Map<alloc::string::String, crate::value::Value>

fn serialize<S>(self: &Self, serializer: S) -> Result<<S as >::Ok, <S as >::Error>
where
    S: serde::ser::Serializer

impl<'de> Deserialize for Map<alloc::string::String, crate::value::Value>

fn deserialize<D>(deserializer: D) -> Result<Self, <D as >::Error>
where
    D: de::Deserializer<'de>

impl<'de> Deserializer for crate::map::Map<alloc::string::String, crate::value::Value>

fn deserialize_any<V>(self: Self, visitor: V) -> Result<<V as >::Value, <Self as >::Error>
where
    V: Visitor<'de>
fn deserialize_enum<V>(self: Self, _name: &'static str, _variants: &'static [&'static str], visitor: V) -> Result<<V as >::Value, <Self as >::Error>
where
    V: Visitor<'de>
fn deserialize_ignored_any<V>(self: Self, visitor: V) -> Result<<V as >::Value, <Self as >::Error>
where
    V: Visitor<'de>
fn deserialize_bool<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_i8<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_i16<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_i32<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_i64<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_i128<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_u8<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_u16<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_u32<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_u64<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_u128<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_f32<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_f64<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_char<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_str<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_string<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_bytes<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_byte_buf<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_option<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_unit<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_unit_struct<V>(self: Self, name: &'static str, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_newtype_struct<V>(self: Self, name: &'static str, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_seq<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_tuple<V>(self: Self, len: usize, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_tuple_struct<V>(self: Self, name: &'static str, len: usize, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_map<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_struct<V>(self: Self, name: &'static str, fields: &'static [&'static str], visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>
fn deserialize_identifier<V>(self: Self, visitor: V) -> $crate::__private::Result<<V as >::Value, <Self as $crate::de::Deserializer<'de>>::Error>
where
    V: $crate::de::Visitor<'de>

impl<'de> IntoDeserializer for Map<alloc::string::String, crate::value::Value>

fn into_deserializer(self: Self) -> <Self as >::Deserializer

impl<K, V> Freeze for Map<K, V>

impl<K, V> RefUnwindSafe for Map<K, V>

impl<K, V> Send for Map<K, V>

impl<K, V> Sync for Map<K, V>

impl<K, V> Unpin for Map<K, V>

impl<K, V> UnwindSafe for Map<K, V>

impl<Q> Index for Map<alloc::string::String, crate::value::Value>

fn index(self: &Self, index: &Q) -> &Value

impl<Q> IndexMut for Map<alloc::string::String, crate::value::Value>

fn index_mut(self: &mut Self, index: &Q) -> &mut Value

impl<T> Any for Map<K, V>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Map<K, V>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Map<K, V>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Map<K, V>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> DeserializeOwned for Map<K, V>

impl<T> From for Map<K, V>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Map<K, V>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Map<K, V>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Map<K, V>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Map<K, V>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>