Struct serde_json_bytes::map::Map
source · pub struct Map<K, V> { /* private fields */ }Expand description
Represents a JSON key/value type.
Implementations§
source§impl Map<ByteString, Value>
impl Map<ByteString, 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>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn get<Q>(&self, key: &Q) -> Option<&Value>where ByteString: 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.
sourcepub fn contains_key<Q>(&self, key: &Q) -> boolwhere
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn contains_key<Q>(&self, key: &Q) -> boolwhere ByteString: 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.
sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where ByteString: 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.
sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&ByteString, &Value)>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&ByteString, &Value)>where ByteString: 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.
sourcepub fn insert<K>(&mut self, k: K, v: Value) -> Option<Value>where
K: Into<ByteString>,
pub fn insert<K>(&mut self, k: K, v: Value) -> Option<Value>where K: Into<ByteString>,
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>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>where ByteString: 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.
sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(ByteString, Value)>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(ByteString, Value)>where ByteString: 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.
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<'_>where
S: Into<ByteString>,
pub fn entry<S>(&mut self, key: S) -> Entry<'_>where S: Into<ByteString>,
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<ByteString, Value>
impl<'de> Deserialize<'de> for Map<ByteString, 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<(ByteString, Value)> for Map<ByteString, Value>
impl Extend<(ByteString, Value)> for Map<ByteString, Value>
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (ByteString, Value)>,
fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = (ByteString, Value)>,
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 FromIterator<(ByteString, Value)> for Map<ByteString, Value>
impl FromIterator<(ByteString, Value)> for Map<ByteString, Value>
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = (ByteString, Value)>,
fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = (ByteString, Value)>,
source§impl<'a, Q> Index<&'a Q> for Map<ByteString, Value>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
impl<'a, Q> Index<&'a Q> for Map<ByteString, Value>where ByteString: Borrow<Q>, Q: ?Sized + Ord + Eq + Hash,
Access an element of this map. Panics if the given key is not present in the map.
match *val {
Value::String(ref s) => Some(s.as_str()),
Value::Array(ref arr) => arr[0].as_str(),
Value::Object(ref map) => map["type"].as_str(),
_ => None,
}source§impl<'a, Q> IndexMut<&'a Q> for Map<ByteString, Value>where
ByteString: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
impl<'a, Q> IndexMut<&'a Q> for Map<ByteString, Value>where ByteString: Borrow<Q>, Q: ?Sized + Ord + Eq + Hash,
Mutably access an element of this map. Panics if the given key is not present in the map.
map["key"] = json!("value");