pub struct Map<K, V> { /* private fields */ }
Expand description
Represents a JSON key/value type.
Implementations§
Source§impl Map<String, Value>
impl Map<String, Value>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Makes a new empty Map with the given initial capacity.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&Value>
pub fn get<Q>(&self, key: &Q) -> Option<&Value>
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.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
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.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
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.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
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.
Sourcepub fn insert(&mut self, k: String, v: Value) -> Option<Value>
pub fn insert(&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.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
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.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
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.
Sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Moves all elements from other into self, leaving other empty.
Sourcepub fn entry<S>(&mut self, key: S) -> Entry<'_>
pub fn entry<S>(&mut self, key: S) -> Entry<'_>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
Gets a mutable iterator over the entries of the map.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ
Gets an iterator over mutable values of the map.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Map<String, Value>
impl<'de> Deserialize<'de> for Map<String, Value>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Extend<(String, Value)> for Map<String, Value>
impl Extend<(String, Value)> for Map<String, Value>
Source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a, Q> Index<&'a Q> for Map<String, Value>
impl<'a, Q> Index<&'a Q> for Map<String, Value>
Access an element of this map. Panics if the given key is not present in the map.
match val {
Value::String(s) => Some(s.as_str()),
Value::Array(arr) => arr[0].as_str(),
Value::Object(map) => map["type"].as_str(),
_ => None,
}
Source§impl<'a, Q> IndexMut<&'a Q> for Map<String, Value>
impl<'a, Q> IndexMut<&'a Q> for Map<String, Value>
Mutably access an element of this map. Panics if the given key is not present in the map.
map["key"] = json!("value");