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
impl Mapping
Sourcepub fn with_capacity(capacity: usize) -> Self
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.
Sourcepub fn reserve(&mut self, additional: usize)
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
.
Sourcepub fn shrink_to_fit(&mut self)
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.
Sourcepub fn insert(&mut self, k: Value, v: Value) -> Option<Value>
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.
Sourcepub fn contains_key<I: Index>(&self, index: I) -> bool
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.
Sourcepub fn get<I: Index>(&self, index: I) -> Option<&Value>
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.
Sourcepub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
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.
Sourcepub fn entry(&mut self, k: Value) -> Entry<'_>
pub fn entry(&mut self, k: Value) -> Entry<'_>
Gets the given key’s corresponding entry in the mapping for in-place manipulation.
Sourcepub fn remove<I: Index>(&mut self, index: I) -> Option<Value>
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.
Sourcepub fn remove_entry<I: Index>(&mut self, index: I) -> Option<(Value, Value)>
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.
Sourcepub fn swap_remove<I: Index>(&mut self, index: I) -> Option<Value>
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.
Sourcepub fn swap_remove_entry<I: Index>(
&mut self,
index: I,
) -> Option<(Value, Value)>
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.
Sourcepub fn shift_remove<I: Index>(&mut self, index: I) -> Option<Value>
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.
Sourcepub fn shift_remove_entry<I: Index>(
&mut self,
index: I,
) -> Option<(Value, Value)>
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.
Sourcepub fn retain<F>(&mut self, keep: F)
pub fn retain<F>(&mut self, keep: F)
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v)
such that f(&k, &mut v)
returns false
.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the mapping can hold without reallocating.
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
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)
.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
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)
.
Sourcepub fn keys(&self) -> Keys<'_> ⓘ
pub fn keys(&self) -> Keys<'_> ⓘ
Returns an iterator over the keys of the mapping, in their order.
The iterator element type is &'a Value
.
Sourcepub fn into_keys(self) -> IntoKeys ⓘ
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
.
Sourcepub fn values(&self) -> Values<'_> ⓘ
pub fn values(&self) -> Values<'_> ⓘ
Returns an iterator over the values of the mapping, in their order.
The iterator element type is &'a Value
.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ
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
.
Sourcepub fn into_values(self) -> IntoValues ⓘ
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 Debug for Mapping
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§impl<'de> Deserialize<'de> for Mapping
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Extend<(Value, Value)> for Mapping
impl Extend<(Value, Value)> for Mapping
Source§fn extend<I: IntoIterator<Item = (Value, Value)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (Value, Value)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl From<Mapping> for Value
impl From<Mapping> for Value
Source§fn from(f: Mapping) -> Self
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<I> Index<I> for Mappingwhere
I: Index,
impl<I> Index<I> for Mappingwhere
I: Index,
Mapping
is ordered if its keys and values are ordered.
Source§impl<I> IndexMut<I> for Mappingwhere
I: Index,
impl<I> IndexMut<I> for Mappingwhere
I: Index,
Mapping
is ordered if its keys and values are ordered.
Source§impl<'a> IntoIterator for &'a Mapping
impl<'a> IntoIterator for &'a Mapping
Source§impl<'a> IntoIterator for &'a mut Mapping
impl<'a> IntoIterator for &'a mut Mapping
Source§impl IntoIterator for Mapping
impl IntoIterator for Mapping
Source§impl PartialOrd for Mapping
impl PartialOrd for Mapping
Mapping
is ordered if its keys and values are ordered.
impl Eq for Mapping
impl StructuralPartialEq for Mapping
Auto Trait Implementations§
impl Freeze for Mapping
impl RefUnwindSafe for Mapping
impl Send for Mapping
impl Sync for Mapping
impl Unpin for Mapping
impl UnwindSafe for Mapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.