pub struct NonEmptyIndexSet<K, S = RandomState> { /* private fields */ }Expand description
A wrapper around ::indexmap::IndexSet that is guaranteed to have at least one element by the
Rust’s type system: it consists of a first element and an indexed set (which could be
empty) rest elements.
Implementations§
Source§impl<K> NonEmptyIndexSet<K, RandomState>
impl<K> NonEmptyIndexSet<K, RandomState>
Sourcepub fn with_capacity(first: K, capacity: usize) -> Self
pub fn with_capacity(first: K, capacity: usize) -> Self
Creates a set with a given capacity.
Sourcepub fn from_iterator(i: impl IntoIterator<Item = K>) -> Result<Self, Error>
pub fn from_iterator(i: impl IntoIterator<Item = K>) -> Result<Self, Error>
Creates a set from a given iterator with a default hasher.
Source§impl<K, S> NonEmptyIndexSet<K, S>
impl<K, S> NonEmptyIndexSet<K, S>
Sourcepub fn with_hasher(first: K, hash_builder: S) -> Self
pub fn with_hasher(first: K, hash_builder: S) -> Self
Creates a set with a given hasher.
Sourcepub fn with_capacity_and_hasher(
first: K,
capacity: usize,
hash_builder: S,
) -> Self
pub fn with_capacity_and_hasher( first: K, capacity: usize, hash_builder: S, ) -> Self
Creates a set with a given capacity.
Sourcepub fn iter(&self) -> impl Iterator<Item = &K>
pub fn iter(&self) -> impl Iterator<Item = &K>
Iterates over key-value paris of the set in an immutable way.
Sourcepub fn from_iter_with_hasher(
i: impl IntoIterator<Item = K>,
hasher: S,
) -> Result<Self, Error>
pub fn from_iter_with_hasher( i: impl IntoIterator<Item = K>, hasher: S, ) -> Result<Self, Error>
Creates a set from a given iterator with a given hasher.
Sourcepub fn take<Q>(&mut self, key: &Q) -> Result<Option<K>, Error>
pub fn take<Q>(&mut self, key: &Q) -> Result<Option<K>, Error>
Removes and returns a value from the set that is equal to 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<bool, Error>
pub fn remove<Q>(&mut self, key: &Q) -> Result<bool, Error>
Removes a value from the set that is equal to a given key, if any. Returns true if the
value was present in the set.
An attempt to remove the last element will cause an Error to be returned.
Sourcepub fn insert(&mut self, key: K) -> bool
pub fn insert(&mut self, key: K) -> bool
Adds a value to the set.
If there was no such a value in the set before, true is returned.
If the value is in the set already, it remains unchaged and false is returned.
Sourcepub fn replace(&mut self, key: K) -> Option<K>
pub fn replace(&mut self, key: K) -> Option<K>
Replaces a value in the set with a given one. An old value is returned, if any.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks whether or not the set is empty.
As one would expect it always evaluates to false :)
assert!(!NonEmptyIndexSet::new("key").is_empty());Sourcepub fn get_first_mut(&mut self) -> &mut K
pub fn get_first_mut(&mut self) -> &mut K
Gets a mutable reference to the first element.
Sourcepub fn get_rest(&self) -> &IndexSet<K, S>
pub fn get_rest(&self) -> &IndexSet<K, S>
Gets an immutable reference to the rest indexed set of elements.
Sourcepub fn get_rest_mut(&mut self) -> &mut IndexSet<K, S>
pub fn get_rest_mut(&mut self) -> &mut IndexSet<K, S>
Gets a mutable reference to the rest indexed set 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 set.
Trait Implementations§
Source§impl<K: Clone, S: Clone> Clone for NonEmptyIndexSet<K, S>
impl<K: Clone, S: Clone> Clone for NonEmptyIndexSet<K, S>
Source§fn clone(&self) -> NonEmptyIndexSet<K, S>
fn clone(&self) -> NonEmptyIndexSet<K, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K, S> Debug for NonEmptyIndexSet<K, S>
impl<K, S> Debug for NonEmptyIndexSet<K, S>
Source§impl<'de, K, S> Deserialize<'de> for NonEmptyIndexSet<K, S>
impl<'de, K, S> Deserialize<'de> for NonEmptyIndexSet<K, 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, S> Extend<K> for NonEmptyIndexSet<K, S>
impl<K, S> Extend<K> for NonEmptyIndexSet<K, S>
Source§fn extend<T: IntoIterator<Item = K>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = K>>(&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, S: BuildHasher> Into<IndexSet<K, S>> for NonEmptyIndexSet<K, S>
impl<K: Eq + Hash, S: BuildHasher> Into<IndexSet<K, S>> for NonEmptyIndexSet<K, S>
Source§impl<K, S> IntoIterator for NonEmptyIndexSet<K, S>
impl<K, S> IntoIterator for NonEmptyIndexSet<K, S>
Source§impl<K, S1, S2> PartialEq<NonEmptyIndexSet<K, S1>> for NonEmptyIndexSet<K, S2>
impl<K, S1, S2> PartialEq<NonEmptyIndexSet<K, S1>> for NonEmptyIndexSet<K, S2>
Source§impl<K, H> Serialize for NonEmptyIndexSet<K, H>
impl<K, H> Serialize for NonEmptyIndexSet<K, H>
impl<K, S> Eq for NonEmptyIndexSet<K, S>
Auto Trait Implementations§
impl<K, S> Freeze for NonEmptyIndexSet<K, S>
impl<K, S> RefUnwindSafe for NonEmptyIndexSet<K, S>where
K: RefUnwindSafe,
S: RefUnwindSafe,
impl<K, S> Send for NonEmptyIndexSet<K, S>
impl<K, S> Sync for NonEmptyIndexSet<K, S>
impl<K, S> Unpin for NonEmptyIndexSet<K, S>
impl<K, S> UnwindSafe for NonEmptyIndexSet<K, S>where
K: UnwindSafe,
S: UnwindSafe,
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.