[][src]Struct non_empty_collections::index_map::NonEmptyIndexMap

pub struct NonEmptyIndexMap<K, V, S = RandomState> { /* fields omitted */ }

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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> Extend<(K, V)> for NonEmptyIndexMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

impl<K: Clone, V: Clone, S: Clone> Clone 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]

impl<K, V, S> IntoIterator for NonEmptyIndexMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

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?

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]

impl<K, V, S> Debug for NonEmptyIndexMap<K, V, S> where
    K: Eq + Hash + Debug,
    V: Debug,
    S: BuildHasher
[src]

impl<K, V, H> Serialize for NonEmptyIndexMap<K, V, H> where
    K: Serialize,
    V: Serialize,
    K: Eq + Hash,
    H: BuildHasher
[src]

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]

Auto Trait Implementations

impl<K, V, S> Send for NonEmptyIndexMap<K, V, S> where
    K: Send,
    S: Send,
    V: Send

impl<K, V, S> Sync for NonEmptyIndexMap<K, V, S> where
    K: Sync,
    S: Sync,
    V: Sync

impl<K, V, S> Unpin for NonEmptyIndexMap<K, V, S> where
    K: Unpin,
    S: Unpin,
    V: Unpin

impl<K, V, S> RefUnwindSafe for NonEmptyIndexMap<K, V, S> where
    K: RefUnwindSafe,
    S: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V, S> UnwindSafe for NonEmptyIndexMap<K, V, S> where
    K: UnwindSafe,
    S: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

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?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]