serde_yaml::mapping

Struct Mapping

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

A YAML mapping in which the keys and values are both serde_yaml::Value.

Implementations§

source§

impl Mapping

source

pub fn new() -> Self

Creates an empty YAML map.

source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty YAML map with the given initial capacity.

source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted into the map. The map may reserve more space to avoid frequent allocations.

§Panics

Panics if the new allocation size overflows usize.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

source

pub fn insert(&mut self, k: Value, v: Value) -> Option<Value>

Inserts a key-value pair into the map. If the key already existed, the old value is returned.

source

pub fn contains_key<I: Index>(&self, index: I) -> bool

Checks if the map contains the given key.

source

pub fn get<I: Index>(&self, index: I) -> Option<&Value>

Returns the value corresponding to the key in the map.

source

pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>

Returns the mutable reference corresponding to the key in the map.

source

pub fn entry(&mut self, k: Value) -> Entry<'_>

Gets the given key’s corresponding entry in the map for insertion and/or in-place manipulation.

source

pub fn remove<I: Index>(&mut self, index: I) -> Option<Value>

Removes and returns the value corresponding to the key from the map.

This is equivalent to .swap_remove(index), replacing this entry’s position with the last element. If you need to preserve the relative order of the keys in the map, use .shift_remove(key) instead.

source

pub fn remove_entry<I: Index>(&mut self, index: I) -> Option<(Value, Value)>

Remove and return the key-value pair.

This is equivalent to .swap_remove_entry(index), replacing this entry’s position with the last element. If you need to preserve the relative order of the keys in the map, use .shift_remove_entry(key) instead.

source

pub fn swap_remove<I: Index>(&mut self, index: I) -> Option<Value>

Removes and returns the value corresponding to the key from the map.

Like Vec::swap_remove, the entry is removed by swapping it with the last element of the map and popping it off. This perturbs the position of what used to be the last element!

source

pub fn swap_remove_entry<I: Index>( &mut self, index: I, ) -> Option<(Value, Value)>

Remove and return the key-value pair.

Like Vec::swap_remove, the entry is removed by swapping it with the last element of the map and popping it off. This perturbs the position of what used to be the last element!

source

pub fn shift_remove<I: Index>(&mut self, index: I) -> Option<Value>

Removes and returns the value corresponding to the key from the map.

Like Vec::remove, the entry is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

source

pub fn shift_remove_entry<I: Index>( &mut self, index: I, ) -> Option<(Value, Value)>

Remove and return the key-value pair.

Like Vec::remove, the entry is removed by shifting all of the elements that follow it, preserving their relative order. This perturbs the index of all of those elements!

source

pub fn retain<F>(&mut self, keep: F)
where F: FnMut(&Value, &mut Value) -> bool,

Scan through each key-value pair in the map and keep those where the closure keep returns true.

source

pub fn capacity(&self) -> usize

Returns the maximum number of key-value pairs the map can hold without reallocating.

source

pub fn len(&self) -> usize

Returns the number of key-value pairs in the map.

source

pub fn is_empty(&self) -> bool

Returns whether the map is currently empty.

source

pub fn clear(&mut self)

Clears the map of all key-value pairs.

source

pub fn iter(&self) -> Iter<'_>

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a Value, &'a Value).

source

pub fn iter_mut(&mut self) -> IterMut<'_>

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a Value, &'a mut ValuE).

source

pub fn keys(&self) -> Keys<'_>

Return an iterator over the keys of the map.

source

pub fn into_keys(self) -> IntoKeys

Return an owning iterator over the keys of the map.

source

pub fn values(&self) -> Values<'_>

Return an iterator over the values of the map.

source

pub fn values_mut(&mut self) -> ValuesMut<'_>

Return an iterator over mutable references to the values of the map.

source

pub fn into_values(self) -> IntoValues

Return an owning iterator over the values of the map.

Trait Implementations§

source§

impl Clone for Mapping

source§

fn clone(&self) -> Mapping

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Mapping

source§

fn fmt(&self, formatter: &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<'de> Deserialize<'de> for Mapping

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Extend<(Value, Value)> for Mapping

source§

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

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<Mapping> for Value

source§

fn from(f: Mapping) -> Self

Convert map (with string keys) to Value

§Examples
use serde_yaml::{Mapping, Value};

let mut m = Mapping::new();
m.insert("Lorem".into(), "ipsum".into());
let x: Value = m.into();
source§

impl FromIterator<(Value, Value)> for Mapping

source§

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

Creates a value from an iterator. Read more
source§

impl Hash for Mapping

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<I> Index<I> for Mapping
where I: Index,

source§

type Output = Value

The returned type after indexing.
source§

fn index(&self, index: I) -> &Value

Performs the indexing (container[index]) operation. Read more
source§

impl<I> IndexMut<I> for Mapping
where I: Index,

source§

fn index_mut(&mut self, index: I) -> &mut Value

Performs the mutable indexing (container[index]) operation. 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 = Iter<'a>

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 Value, &'a mut Value)

The type of the elements being iterated over.
source§

type IntoIter = IterMut<'a>

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 IntoIterator for Mapping

source§

type Item = (Value, Value)

The type of the elements being iterated over.
source§

type IntoIter = IntoIter

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Mapping

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Mapping

source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Mapping

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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, 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,