pub enum Entry<'a, K: AsYaml> {
Occupied(OccupiedEntry<'a>),
Vacant(VacantEntry<'a, K>),
}Expand description
A view into a single entry in a Mapping, which may either be vacant
or occupied.
Obtained from Mapping::entry.
Variants§
Occupied(OccupiedEntry<'a>)
The key is already present in the mapping.
Vacant(VacantEntry<'a, K>)
The key is not present in the mapping.
Implementations§
Source§impl<'a, K: AsYaml> Entry<'a, K>
impl<'a, K: AsYaml> Entry<'a, K>
Sourcepub fn or_insert(self, default: impl AsYaml) -> YamlNode
pub fn or_insert(self, default: impl AsYaml) -> YamlNode
Ensure a value is in the entry by inserting default if vacant, and
return the resulting value as a YamlNode.
Sourcepub fn or_insert_with<V, F>(self, default: F) -> YamlNode
pub fn or_insert_with<V, F>(self, default: F) -> YamlNode
Ensure a value is in the entry by inserting the result of default if
vacant, and return the resulting value as a YamlNode.
default is only called if the entry is vacant.
Sourcepub fn or_insert_mapping(self) -> Mapping
pub fn or_insert_mapping(self) -> Mapping
Ensure the entry holds a Mapping and return it.
If the entry is vacant, an empty mapping is inserted. If the entry is occupied but the value is not a mapping, it is replaced with an empty mapping. Otherwise the existing nested mapping is returned unchanged.
Sourcepub fn or_insert_sequence(self) -> Sequence
pub fn or_insert_sequence(self) -> Sequence
Ensure the entry holds a Sequence and return it.
If the entry is vacant, an empty sequence is inserted. If the entry is occupied but the value is not a sequence, it is replaced with an empty sequence. Otherwise the existing nested sequence is returned unchanged.
Sourcepub fn and_modify<F>(self, f: F) -> Selfwhere
F: FnOnce(&OccupiedEntry<'a>),
pub fn and_modify<F>(self, f: F) -> Selfwhere
F: FnOnce(&OccupiedEntry<'a>),
Provide in-place access to an occupied entry before any potential inserts.
The closure is only called if the entry is occupied. Returns self
unchanged so calls can be chained with or_insert
and friends.
The tree uses interior mutability, so the closure receives a shared
reference; OccupiedEntry::set_value and friends still work through
&self.