Skip to main content

Mapping

Struct Mapping 

Source
pub struct Mapping { /* private fields */ }
Expand description

An ordered YAML mapping (preserves insertion / source order, like the reference implementation which dumps with sort_keys=False).

Keys are Values for generality, but OKF frontmatter keys are always strings; the get / insert helpers operate on string keys for convenience.

Implementations§

Source§

impl Mapping

Source

pub const fn new() -> Self

Creates an empty mapping.

Source

pub const fn len(&self) -> usize

Number of key/value pairs.

Source

pub const fn is_empty(&self) -> bool

Returns true if the mapping has no entries.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Looks up a value by string key.

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

Looks up a mutable value by string key.

Source

pub fn contains_key(&self, key: &str) -> bool

Returns true if the mapping contains the given string key.

Source

pub fn insert(&mut self, key: impl Into<String>, value: Value) -> Option<Value>

Inserts (or, if the string key already exists, replaces) a value, preserving the position of an existing key. Returns the previous value.

Source

pub fn remove(&mut self, key: &str) -> Option<Value>

Removes a value by string key, preserving order of the rest.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Value, &Value)>

Iterates over (key, value) pairs in order.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&mut Value, &mut Value)>

Iterates over mutable (key, value) pairs in order.

Source

pub fn keys(&self) -> impl Iterator<Item = &str>

Iterates over string keys (skipping any non-string keys).

Source

pub fn values(&self) -> impl Iterator<Item = &Value>

Iterates over values in order.

Source

pub fn entries(&self) -> &[(Value, Value)]

Borrows the underlying slice of key-value entry pairs.

Trait Implementations§

Source§

impl Clone for Mapping

Source§

fn clone(&self) -> Mapping

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mapping

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Mapping

Source§

fn default() -> Mapping

Returns the “default value” for a type. Read more
Source§

impl Display for Mapping

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Extend<(&'a str, Value)> for Mapping

Source§

fn extend<T: IntoIterator<Item = (&'a str, Value)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<(String, Value)> for Mapping

Source§

fn extend<T: IntoIterator<Item = (String, Value)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<(Value, Value)> for Mapping

Source§

fn extend<T: IntoIterator<Item = (Value, Value)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Frontmatter> for Mapping

Source§

fn from(fm: Frontmatter) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for Frontmatter

Source§

fn from(map: Mapping) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for Value

Source§

fn from(m: Mapping) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<(&'a str, Value)> for Mapping

Source§

fn from_iter<T: IntoIterator<Item = (&'a str, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<(String, Value)> for Mapping

Source§

fn from_iter<T: IntoIterator<Item = (String, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<(Value, Value)> for Mapping

Source§

fn from_iter<T: IntoIterator<Item = (Value, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl IntoIterator for Mapping

Source§

type Item = (Value, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(Value, Value)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a Mapping

Source§

type Item = (&'a Value, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'a, (Value, Value)>, fn(&(Value, Value)) -> (&Value, &Value)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Mapping

Source§

type Item = (&'a mut Value, &'a mut Value)

The type of the elements being iterated over.
Source§

type IntoIter = Map<IterMut<'a, (Value, Value)>, fn(&mut (Value, Value)) -> (&mut Value, &mut Value)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Mapping

Source§

fn eq(&self, other: &Mapping) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mapping

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.