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
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.