pub struct NonEmptyIndexMap<K, V, S = RandomState> { /* private fields */ }Expand description
A wrapper around ::indexmap::IndexMap that is guaranteed to have at least one element by the
Rust’s type system: it consists of a first element and an indexed map (which could be
empty) rest elements.
Implementations§
Source§impl<K, V> NonEmptyIndexMap<K, V, RandomState>
impl<K, V> NonEmptyIndexMap<K, V, RandomState>
Sourcepub fn with_capacity(key: K, value: V, capacity: usize) -> Self
pub fn with_capacity(key: K, value: V, capacity: usize) -> Self
Creates a map with a given capacity.
Sourcepub fn from_item_and_iterator(
key: K,
value: V,
i: impl IntoIterator<Item = (K, V)>,
) -> Self
pub fn from_item_and_iterator( key: K, value: V, i: impl IntoIterator<Item = (K, V)>, ) -> Self
Creates a map from an item (a key and a value pair) standart hash map.
Sourcepub fn from_iterator(i: impl IntoIterator<Item = (K, V)>) -> Result<Self, Error>
pub fn from_iterator(i: impl IntoIterator<Item = (K, V)>) -> Result<Self, Error>
Creates a map from a given iterator with a default hasher.
Source§impl<K, V, S> NonEmptyIndexMap<K, V, S>
impl<K, V, S> NonEmptyIndexMap<K, V, S>
Sourcepub fn with_hasher(key: K, value: V, hash_builder: S) -> Self
pub fn with_hasher(key: K, value: V, hash_builder: S) -> Self
Creates a map with a given hasher.
Sourcepub fn with_capacity_and_hasher(
key: K,
value: V,
capacity: usize,
hash_builder: S,
) -> Self
pub fn with_capacity_and_hasher( key: K, value: V, capacity: usize, hash_builder: S, ) -> Self
Creates a map with a given capacity and a given hasher.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Iterates over key-value pairs of the map in an immutable way.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
Iterates over key-value pairs of the map in a mutable way.
Sourcepub fn from_iter_with_hasher(
i: impl IntoIterator<Item = (K, V)>,
hasher: S,
) -> Result<Self, Error>
pub fn from_iter_with_hasher( i: impl IntoIterator<Item = (K, V)>, hasher: S, ) -> Result<Self, Error>
Creates a map from a given iterator with a given hasher.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Gets a value associated with a given key, if any.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Result<Option<(K, V)>, Error>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Result<Option<(K, V)>, Error>
Removes and returns an element associated with a given key, if any.
An attempt to remove the last element will cause an Error to be returned.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Result<Option<V>, Error>
pub fn remove<Q>(&mut self, key: &Q) -> Result<Option<V>, Error>
Removes and element associated with a given key and return its value, if any.
An attempt to remove the last element will cause an Error to be returned.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the map. If the map have already had an element associated with a given key, the associated value is updated and the old one is returned.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks whether or not the map is empty.
As one would expect it always evaluates to false :)
assert!(!NonEmptyIndexMap::new("key", "value").is_empty());Sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
Returns an entry that corresponds to a given key.
Sourcepub fn get_first(&self) -> (&K, &V)
pub fn get_first(&self) -> (&K, &V)
Gets an immutable reference to the firs element (only the value).
Sourcepub fn get_first_mut(&mut self) -> (&mut K, &mut V)
pub fn get_first_mut(&mut self) -> (&mut K, &mut V)
Gets a mutable reference to the firs element (only the value).
Sourcepub fn get_rest(&self) -> &IndexMap<K, V, S>
pub fn get_rest(&self) -> &IndexMap<K, V, S>
Gets an immutable reference to the rest indexed map of elements.
Sourcepub fn get_rest_mut(&mut self) -> &mut IndexMap<K, V, S>
pub fn get_rest_mut(&mut self) -> &mut IndexMap<K, V, S>
Gets a mutable reference to the rest indexed map of elements.
Sourcepub fn remove_first(&mut self) -> Result<(), Error>
pub fn remove_first(&mut self) -> Result<(), Error>
Attempts to remove the first element. Will fail if it is the only one element in the map.
Trait Implementations§
Source§impl<K: Clone, V: Clone, S: Clone> Clone for NonEmptyIndexMap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for NonEmptyIndexMap<K, V, S>
Source§fn clone(&self) -> NonEmptyIndexMap<K, V, S>
fn clone(&self) -> NonEmptyIndexMap<K, V, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K, V, S> Debug for NonEmptyIndexMap<K, V, S>
impl<K, V, S> Debug for NonEmptyIndexMap<K, V, S>
Source§impl<'de, K, V, S> Deserialize<'de> for NonEmptyIndexMap<K, V, S>
impl<'de, K, V, S> Deserialize<'de> for NonEmptyIndexMap<K, V, S>
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<K, V, S> Extend<(K, V)> for NonEmptyIndexMap<K, V, S>
impl<K, V, S> Extend<(K, V)> for NonEmptyIndexMap<K, V, S>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
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<K: Eq + Hash, V, S: BuildHasher> Into<IndexMap<K, V, S>> for NonEmptyIndexMap<K, V, S>
impl<K: Eq + Hash, V, S: BuildHasher> Into<IndexMap<K, V, S>> for NonEmptyIndexMap<K, V, S>
Source§impl<K, V, S> IntoIterator for NonEmptyIndexMap<K, V, S>
impl<K, V, S> IntoIterator for NonEmptyIndexMap<K, V, S>
Source§impl<K, V, S1, S2> PartialEq<NonEmptyIndexMap<K, V, S1>> for NonEmptyIndexMap<K, V, S2>
impl<K, V, S1, S2> PartialEq<NonEmptyIndexMap<K, V, S1>> for NonEmptyIndexMap<K, V, S2>
Source§impl<K, V, H> Serialize for NonEmptyIndexMap<K, V, H>
impl<K, V, H> Serialize for NonEmptyIndexMap<K, V, H>
impl<K, V, S> Eq for NonEmptyIndexMap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for NonEmptyIndexMap<K, V, S>
impl<K, V, S> RefUnwindSafe for NonEmptyIndexMap<K, V, S>
impl<K, V, S> Send for NonEmptyIndexMap<K, V, S>
impl<K, V, S> Sync for NonEmptyIndexMap<K, V, S>
impl<K, V, S> Unpin for NonEmptyIndexMap<K, V, S>
impl<K, V, S> UnwindSafe for NonEmptyIndexMap<K, V, S>
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§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.