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
impl Mapping
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty YAML map with the given initial capacity.
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 map. The map may reserve more space to avoid frequent
allocations.
§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 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.
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 map. If the key already existed, 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
Checks if the map contains the given key.
sourcepub fn get<I: Index>(&self, index: I) -> Option<&Value>
pub fn get<I: Index>(&self, index: I) -> Option<&Value>
Returns the value corresponding to the key in the map.
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 the mutable reference corresponding to the key in the map.
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 map for insertion and/or 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 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.
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)>
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.
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 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!
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)>
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!
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 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!
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)>
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!
sourcepub fn retain<F>(&mut self, keep: F)
pub fn retain<F>(&mut self, keep: F)
Scan through each key-value pair in the map and keep those where the
closure keep
returns true.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the maximum number of key-value pairs the map can hold without reallocating.
sourcepub fn iter(&self) -> Iter<'_> ⓘ
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)
.
sourcepub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
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)
.
sourcepub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_> ⓘ
Return an iterator over mutable references to the values of the map.
sourcepub fn into_values(self) -> IntoValues ⓘ
pub fn into_values(self) -> IntoValues ⓘ
Return an owning iterator over the values of the map.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Mapping
impl<'de> Deserialize<'de> for Mapping
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<'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
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.