Skip to main content

Entry

Enum Entry 

Source
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>

Source

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.

Source

pub fn or_insert_with<V, F>(self, default: F) -> YamlNode
where V: AsYaml, F: FnOnce() -> V,

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.

Source

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.

Source

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.

Source

pub fn and_modify<F>(self, f: F) -> Self
where 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.

Source

pub fn key(&self) -> Option<YamlNode>

Return the key that this entry refers to, as a YamlNode.

For an occupied entry this is the existing key node in the tree. For a vacant entry it is the key that would be inserted, rendered as a fresh scalar node.

Trait Implementations§

Source§

impl<'a, K: Debug + AsYaml> Debug for Entry<'a, K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, K> !RefUnwindSafe for Entry<'a, K>

§

impl<'a, K> !Send for Entry<'a, K>

§

impl<'a, K> !Sync for Entry<'a, K>

§

impl<'a, K> !UnwindSafe for Entry<'a, K>

§

impl<'a, K> Freeze for Entry<'a, K>
where VacantEntry<'a, K>: Freeze,

§

impl<'a, K> Unpin for Entry<'a, K>
where VacantEntry<'a, K>: Unpin,

§

impl<'a, K> UnsafeUnpin for Entry<'a, K>
where VacantEntry<'a, K>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.