serde_yml

Struct 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
§

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

§

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

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

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

§

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