NonEmptyIndexMap

Struct NonEmptyIndexMap 

Source
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>

Source

pub fn new(key: K, value: V) -> Self

Creates a map with a default hasher.

Source

pub fn with_capacity(key: K, value: V, capacity: usize) -> Self

Creates a map with a given capacity.

Source

pub fn from_item_and_iterator( 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.

Source

pub fn from_iterator(i: impl IntoIterator<Item = (K, V)>) -> Result<Self, Error>
where K: Hash + Eq,

Creates a map from a given iterator with a default hasher.

Source§

impl<K, V, S> NonEmptyIndexMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

Source

pub fn with_hasher(key: K, value: V, hash_builder: S) -> Self

Creates a map with a given hasher.

Source

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.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>

Iterates over key-value pairs of the map in an immutable way.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>

Iterates over key-value pairs of the map in a mutable way.

Source

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.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets a value associated with a given key, if any.

Source

pub fn contains<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Checks whether a given key exists in the map.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Gets a value associated with a given key, if any.

Source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Result<Option<(K, V)>, Error>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Result<Option<V>, Error>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

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());
Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>

Returns an entry that corresponds to a given key.

Source

pub fn get_first(&self) -> (&K, &V)

Gets an immutable reference to the firs element (only the value).

Source

pub fn get_first_mut(&mut self) -> (&mut K, &mut V)

Gets a mutable reference to the firs element (only the value).

Source

pub fn get_rest(&self) -> &IndexMap<K, V, S>

Gets an immutable reference to the rest indexed map of elements.

Source

pub fn get_rest_mut(&mut self) -> &mut IndexMap<K, V, S>

Gets a mutable reference to the rest indexed map of elements.

Source

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.

Source

pub fn retain<F>(&mut self, keep: F) -> Result<(), Error>
where 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§

Source§

impl<K: Clone, V: Clone, S: Clone> Clone for NonEmptyIndexMap<K, V, S>

Source§

fn clone(&self) -> NonEmptyIndexMap<K, V, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, K, V, S> Deserialize<'de> for NonEmptyIndexMap<K, V, S>
where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, S: BuildHasher + Default,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K, V, S> Extend<(K, V)> for NonEmptyIndexMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

Source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Eq + Hash, V, S: BuildHasher> Into<IndexMap<K, V, S>> for NonEmptyIndexMap<K, V, S>

Source§

fn into(self) -> IndexMap<K, V, S>

Converts this type into the (usually inferred) input type.
Source§

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

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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,

Source§

fn eq(&self, other: &NonEmptyIndexMap<K, V, S1>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<K, V, S> Eq for NonEmptyIndexMap<K, V, S>
where K: Hash + Eq, V: Eq, S: BuildHasher,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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