Struct serde_yml::mapping::Mapping

source ·
pub struct Mapping {
    pub map: IndexMap<Value, Value>,
}
Expand description

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

Fields§

§map: IndexMap<Value, Value>

The underlying map.

Implementations§

source§

impl Mapping

source

pub fn new() -> Self

Creates an empty YAML mapping.

source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty YAML mapping with the given initial capacity.

The mapping will be able to hold at least capacity elements without reallocating. If capacity is 0, the mapping will not allocate.

source

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

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

§Panics

Panics if the new allocation size overflows usize.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the mapping 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 mapping.

If the mapping did not have this key present, None is returned.

If the mapping did have this key present, the value is updated, and the old value is returned.

source

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

Returns true if the mapping contains a value for the specified key.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

source

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

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

source

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

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

source

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

Gets the given key’s corresponding entry in the mapping for in-place manipulation.

source

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

Removes a key from the mapping, returning the value at the key if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

This is equivalent to calling swap_remove and ignores the order of the elements.

source

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

Removes a key from the mapping, returning the stored key and value if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

This is equivalent to calling swap_remove_entry and ignores the order of the elements.

source

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

Removes a key from the mapping, returning the value at the key if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

The element is removed by swapping it with the last element of the mapping and popping it off. This perturbs the position of the last element.

source

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

Removes a key from the mapping, returning the stored key and value if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

The element is removed by swapping it with the last element of the mapping and popping it off. This perturbs the position of the last element.

source

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

Removes a key from the mapping, returning the value at the key if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

The element 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)>

Removes a key from the mapping, returning the stored key and value if the key was previously in the mapping.

The key may be any borrowed form of the mapping’s key type, but the ordering on the borrowed form must match the key type’s ordering.

The element 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,

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k, &mut v) returns false.

source

pub fn capacity(&self) -> usize

Returns the number of elements the mapping can hold without reallocating.

source

pub fn len(&self) -> usize

Returns the number of elements in the mapping.

source

pub fn is_empty(&self) -> bool

Returns true if the mapping contains no elements.

source

pub fn clear(&mut self)

Clears the mapping, removing all key-value pairs.

source

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

Returns an iterator over the key-value pairs of the mapping, in their order.

The iterator element type is (&'a Value, &'a Value).

source

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

Returns a mutable iterator over the key-value pairs of the mapping, in their order.

The iterator element type is (&'a Value, &'a mut Value).

source

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

Returns an iterator over the keys of the mapping, in their order.

The iterator element type is &'a Value.

source

pub fn into_keys(self) -> IntoKeys

Returns an owning iterator over the keys of the mapping, in their order.

The iterator element type is Value.

source

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

Returns an iterator over the values of the mapping, in their order.

The iterator element type is &'a Value.

source

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

Returns a mutable iterator over the values of the mapping, in their order.

The iterator element type is &'a mut Value.

source

pub fn into_values(self) -> IntoValues

Returns an owning iterator over the values of the mapping, in their order.

The iterator element type is Value.

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

Implements the Debug trait for Mapping. This allows for customized formatting when debugging Mapping instances.

§Examples

use serde_yml::{Mapping, Value};

let mut mapping = Mapping::new();
mapping.insert(Value::String("name".to_string()), Value::String("John".to_string()));
mapping.insert(Value::String("age".to_string()), Value::Number(30.into()));
println!("{:?}", mapping);
// Output: Mapping {"name": String("John"), "age": Number(30)}
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

Mapping implements Deserialize using the serde crate.

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_yml::{Mapping, Value};

let mut m = Mapping::new();
m.insert("Lorem".into(), "ipsum".into());
let x: Value = m.into();
assert_eq!(x, Value::Mapping(Mapping::from_iter(vec![("Lorem".into(), "ipsum".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

Mapping is hashable if its keys and values are hashable.

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,

Mapping is ordered if its keys and values are ordered.

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,

Mapping is ordered if its keys and values are ordered.

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

Mapping is ordered if its keys and values are ordered.

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

Mapping implements Serialize using the serde crate.

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