[−][src]Struct non_empty_collections::index_map::NonEmptyIndexMap
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.
Methods
impl<K, V> NonEmptyIndexMap<K, V, RandomState>
[src]
pub fn new(key: K, value: V) -> Self
[src]
Creates a map with a default hasher.
pub fn with_capacity(key: K, value: V, capacity: usize) -> Self
[src]
Creates a map with a given capacity.
pub fn from_item_and_iterator(
key: K,
value: V,
i: impl IntoIterator<Item = (K, V)>
) -> Self where
K: Hash + Eq,
[src]
key: K,
value: V,
i: impl IntoIterator<Item = (K, V)>
) -> Self where
K: Hash + Eq,
Creates a map from an item (a key and a value pair) standart hash map.
pub fn from_iterator(i: impl IntoIterator<Item = (K, V)>) -> Result<Self, Error> where
K: Hash + Eq,
[src]
K: Hash + Eq,
Creates a map from a given iterator with a default hasher.
impl<K, V, S> NonEmptyIndexMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
pub fn with_hasher(key: K, value: V, hash_builder: S) -> Self
[src]
Creates a map with a given hasher.
pub fn with_capacity_and_hasher(
key: K,
value: V,
capacity: usize,
hash_builder: S
) -> Self
[src]
key: K,
value: V,
capacity: usize,
hash_builder: S
) -> Self
Creates a map with a given capacity and a given hasher.
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
[src]
Iterates over key-value pairs of the map in an immutable way.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
[src]
Iterates over key-value pairs of the map in a mutable way.
pub fn from_iter_with_hasher(
i: impl IntoIterator<Item = (K, V)>,
hasher: S
) -> Result<Self, Error>
[src]
i: impl IntoIterator<Item = (K, V)>,
hasher: S
) -> Result<Self, Error>
Creates a map from a given iterator with a given hasher.
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
Gets a value associated with a given key, if any.
pub fn contains<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
Checks whether a given key exists in the map.
pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
Gets a value associated with a given key, if any.
pub fn remove_entry<Q: ?Sized>(
&mut self,
key: &Q
) -> Result<Option<(K, V)>, Error> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
&mut self,
key: &Q
) -> Result<Option<(K, V)>, Error> where
K: Borrow<Q>,
Q: Eq + Hash,
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.
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Result<Option<V>, Error> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
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.
pub fn insert(&mut self, key: K, value: V) -> Option<V>
[src]
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.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the map.
pub fn is_empty(&self) -> bool
[src]
Checks whether or not the map is empty.
As one would expect it always evaluates to false
:)
assert!(!NonEmptyIndexMap::new("key", "value").is_empty());
pub fn entry(&mut self, key: K) -> Entry<K, V, S>
[src]
Returns an entry that corresponds to a given key.
pub fn get_first(&self) -> (&K, &V)
[src]
Gets an immutable reference to the firs element (only the value).
pub fn get_first_mut(&mut self) -> (&mut K, &mut V)
[src]
Gets a mutable reference to the firs element (only the value).
pub fn get_rest(&self) -> &IndexMap<K, V, S>
[src]
Gets an immutable reference to the rest indexed map of elements.
pub fn get_rest_mut(&mut self) -> &mut IndexMap<K, V, S>
[src]
Gets a mutable reference to the rest indexed map of elements.
pub fn remove_first(&mut self) -> Result<(), Error>
[src]
Attempts to remove the first element. Will fail if it is the only one element in the map.
pub fn retain<F>(&mut self, keep: F) -> Result<(), Error> where
F: FnMut(&K, &mut V) -> bool,
[src]
F: FnMut(&K, &mut V) -> bool,
Scans the collection and keeps only the items on which the provided keep
function
returns true
. Will fail if in the end only one element will remain.
Trait Implementations
impl<K: Eq + Hash, V, S: BuildHasher> Into<IndexMap<K, V, S>> for NonEmptyIndexMap<K, V, S>
[src]
impl<K, V, S> Eq for NonEmptyIndexMap<K, V, S> where
K: Hash + Eq,
V: Eq,
S: BuildHasher,
[src]
K: Hash + Eq,
V: Eq,
S: BuildHasher,
impl<K: Clone, V: Clone, S: Clone> Clone for NonEmptyIndexMap<K, V, S>
[src]
fn clone(&self) -> NonEmptyIndexMap<K, V, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K, V, S> Extend<(K, V)> for NonEmptyIndexMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
[src]
impl<K, V, S1, S2> PartialEq<NonEmptyIndexMap<K, V, S1>> for NonEmptyIndexMap<K, V, S2> where
K: Hash + Eq,
V: Eq,
S1: BuildHasher,
S2: BuildHasher,
[src]
K: Hash + Eq,
V: Eq,
S1: BuildHasher,
S2: BuildHasher,
fn eq(&self, other: &NonEmptyIndexMap<K, V, S1>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<K, V, S> IntoIterator for NonEmptyIndexMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<K, V, S> Debug for NonEmptyIndexMap<K, V, S> where
K: Eq + Hash + Debug,
V: Debug,
S: BuildHasher,
[src]
K: Eq + Hash + Debug,
V: Debug,
S: BuildHasher,
impl<K, V, H> Serialize for NonEmptyIndexMap<K, V, H> where
K: Serialize,
V: Serialize,
K: Eq + Hash,
H: BuildHasher,
[src]
K: Serialize,
V: Serialize,
K: Eq + Hash,
H: BuildHasher,
impl<'de, K, V, S> Deserialize<'de> for NonEmptyIndexMap<K, V, S> where
K: Deserialize<'de>,
V: Deserialize<'de>,
K: Eq + Hash,
S: BuildHasher + Default,
[src]
K: Deserialize<'de>,
V: Deserialize<'de>,
K: Eq + Hash,
S: BuildHasher + Default,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Auto Trait Implementations
impl<K, V, S> Send for NonEmptyIndexMap<K, V, S> where
K: Send,
S: Send,
V: Send,
K: Send,
S: Send,
V: Send,
impl<K, V, S> Unpin for NonEmptyIndexMap<K, V, S> where
K: Unpin,
S: Unpin,
V: Unpin,
K: Unpin,
S: Unpin,
V: Unpin,
impl<K, V, S> Sync for NonEmptyIndexMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync,
K: Sync,
S: Sync,
V: Sync,
impl<K, V, S> UnwindSafe for NonEmptyIndexMap<K, V, S> where
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
V: UnwindSafe,
impl<K, V, S> RefUnwindSafe for NonEmptyIndexMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,