Struct rocket_dyn_templates::tera::Map
source · 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) -> Map<String, Value>
pub fn with_capacity(capacity: usize) -> Map<String, Value>
Makes a new empty Map with the given initial capacity.
sourcepub fn get<Q>(&self, key: &Q) -> Option<&Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get<Q>(&self, key: &Q) -> Option<&Value>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn contains_key<Q>(&self, key: &Q) -> boolwhere String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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)>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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<(String, Value)>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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 Map<String, Value>)
pub fn append(&mut self, other: &mut Map<String, Value>)
Moves all elements from other into self, leaving other empty.
sourcepub fn entry<S>(&mut self, key: S) -> Entry<'_>where
S: Into<String>,
pub fn entry<S>(&mut self, key: S) -> Entry<'_>where S: Into<String>,
Gets the given key’s corresponding entry in the map for in-place manipulation.
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<Map<String, Value>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Map<String, Value>, <D as Deserializer<'de>>::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)where
T: IntoIterator<Item = (String, Value)>,
fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = (String, 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<'a, Q> Index<&'a Q> for Map<String, Value>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
impl<'a, Q> Index<&'a Q> for Map<String, Value>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
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>where
String: Borrow<Q>,
Q: Ord + Eq + Hash + ?Sized,
impl<'a, Q> IndexMut<&'a Q> for Map<String, Value>where String: Borrow<Q>, Q: Ord + Eq + Hash + ?Sized,
Mutably access an element of this map. Panics if the given key is not present in the map.
map["key"] = json!("value");
source§impl PartialEq<Map<String, Value>> for Map<String, Value>
impl PartialEq<Map<String, Value>> for Map<String, Value>
source§impl Serialize for Map<String, Value>
impl Serialize for Map<String, Value>
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
impl Eq for Map<String, Value>
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for Map<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,
impl<K, V> Send for Map<K, V>where K: Send, V: Send,
impl<K, V> Sync for Map<K, V>where K: Sync, V: Sync,
impl<K, V> Unpin for Map<K, V>
impl<K, V> UnwindSafe for Map<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
§fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where A: Array<Item = T>,
self
into a collection.