pub struct Map<K, V> { /* private fields */ }
Expand description
Represents a TOML 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 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. The key is not updated, though; this matters for
types that can be ==
without being identical.
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.
sourcepub fn retain<F>(&mut self, keep: F)
pub fn retain<F>(&mut self, keep: F)
Retains only the elements specified by the keep
predicate.
In other words, remove all pairs (k, v)
for which keep(&k, &mut v)
returns false
.
The elements are visited in iteration order.
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.
source§impl Map<String, Value>
impl Map<String, Value>
sourcepub fn try_from<T>(value: T) -> Result<Self, Error>where
T: Serialize,
pub fn try_from<T>(value: T) -> Result<Self, Error>where
T: Serialize,
Convert a T
into toml::Table
.
This conversion can fail if T
’s implementation of Serialize
decides to
fail, or if T
contains a map with non-string keys.
sourcepub fn try_into<'de, T>(self) -> Result<T, Error>where
T: Deserialize<'de>,
pub fn try_into<'de, T>(self) -> Result<T, Error>where
T: Deserialize<'de>,
Interpret a toml::Table
as an instance of type T
.
This conversion can fail if the structure of the Table
does not match the structure
expected by T
, for example if T
is a bool which can’t be mapped to a Table
. It can
also fail if the structure is correct but T
’s implementation of Deserialize
decides
that something is wrong with the data, for example required struct fields are missing from
the TOML map or some number is too big to fit in the expected primitive type.
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.
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.