[−][src]Struct non_empty_collections::index_set::NonEmptyIndexSet
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.
Methods
impl<K> NonEmptyIndexSet<K, RandomState>
[src]
pub fn new(first: K) -> Self
[src]
Creates a set with a default hasher.
pub fn with_capacity(first: K, capacity: usize) -> Self
[src]
Creates a set with a given capacity.
pub fn from_iterator(i: impl IntoIterator<Item = K>) -> Result<Self, Error> where
K: Hash + Eq,
[src]
K: Hash + Eq,
Creates a set from a given iterator with a default hasher.
impl<K, S> NonEmptyIndexSet<K, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
pub fn with_hasher(first: K, hash_builder: S) -> Self
[src]
Creates a set with a given hasher.
pub fn with_capacity_and_hasher(
first: K,
capacity: usize,
hash_builder: S
) -> Self
[src]
first: K,
capacity: usize,
hash_builder: S
) -> Self
Creates a set with a given capacity.
pub fn iter(&self) -> impl Iterator<Item = &K>
[src]
Iterates over key-value paris of the set in an immutable way.
pub fn from_iter_with_hasher(
i: impl IntoIterator<Item = K>,
hasher: S
) -> Result<Self, Error>
[src]
i: impl IntoIterator<Item = K>,
hasher: S
) -> Result<Self, Error>
Creates a set from a given iterator with a given hasher.
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&K> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
Gets a stored key from the set.
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 set.
pub fn take<Q: ?Sized>(&mut self, key: &Q) -> Result<Option<K>, Error> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
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.
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Result<bool, Error> where
K: Borrow<Q>,
Q: Eq + Hash,
[src]
K: Borrow<Q>,
Q: Eq + Hash,
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.
pub fn insert(&mut self, key: K) -> bool
[src]
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.
pub fn replace(&mut self, key: K) -> Option<K>
[src]
Replaces a value in the set with a given one. An old value is returned, if any.
pub fn len(&self) -> usize
[src]
Returns the number of elements in the set.
pub fn is_empty(&self) -> bool
[src]
Checks whether or not the set is empty.
As one would expect it always evaluates to false
:)
assert!(!NonEmptyIndexSet::new("key").is_empty());
pub fn get_first(&self) -> &K
[src]
Gets an immutable reference to the first element.
pub fn get_first_mut(&mut self) -> &mut K
[src]
Gets a mutable reference to the first element.
pub fn get_rest(&self) -> &IndexSet<K, S>
[src]
Gets an immutable reference to the rest indexed set of elements.
pub fn get_rest_mut(&mut self) -> &mut IndexSet<K, S>
[src]
Gets a mutable reference to the rest indexed set 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 set.
pub fn retain<F>(&mut self, keep: F) -> Result<(), Error> where
F: FnMut(&K) -> bool,
[src]
F: FnMut(&K) -> 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, S> Eq for NonEmptyIndexSet<K, S> where
K: Hash + Eq,
S: BuildHasher,
[src]
K: Hash + Eq,
S: BuildHasher,
impl<K: Eq + Hash, S: BuildHasher> Into<IndexSet<K, S>> for NonEmptyIndexSet<K, S>
[src]
impl<K: Clone, S: Clone> Clone for NonEmptyIndexSet<K, S>
[src]
fn clone(&self) -> NonEmptyIndexSet<K, S>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K, S1, S2> PartialEq<NonEmptyIndexSet<K, S1>> for NonEmptyIndexSet<K, S2> where
K: Hash + Eq,
S1: BuildHasher,
S2: BuildHasher,
[src]
K: Hash + Eq,
S1: BuildHasher,
S2: BuildHasher,
fn eq(&self, other: &NonEmptyIndexSet<K, S1>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<K, S> IntoIterator for NonEmptyIndexSet<K, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
type IntoIter = IntoIter<K>
Which kind of iterator are we turning this into?
type Item = K
The type of the elements being iterated over.
fn into_iter(self) -> Self::IntoIter
[src]
impl<K, S> Extend<K> for NonEmptyIndexSet<K, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
fn extend<T: IntoIterator<Item = K>>(&mut self, iter: T)
[src]
impl<K, S> Debug for NonEmptyIndexSet<K, S> where
K: Eq + Hash + Debug,
S: BuildHasher,
[src]
K: Eq + Hash + Debug,
S: BuildHasher,
impl<K, H> Serialize for NonEmptyIndexSet<K, H> where
K: Serialize,
K: Eq + Hash,
H: BuildHasher,
[src]
K: Serialize,
K: Eq + Hash,
H: BuildHasher,
impl<'de, K, S> Deserialize<'de> for NonEmptyIndexSet<K, S> where
K: Deserialize<'de>,
K: Eq + Hash,
S: BuildHasher + Default,
[src]
K: 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, S> Send for NonEmptyIndexSet<K, S> where
K: Send,
S: Send,
K: Send,
S: Send,
impl<K, S> Unpin for NonEmptyIndexSet<K, S> where
K: Unpin,
S: Unpin,
K: Unpin,
S: Unpin,
impl<K, S> Sync for NonEmptyIndexSet<K, S> where
K: Sync,
S: Sync,
K: Sync,
S: Sync,
impl<K, S> RefUnwindSafe for NonEmptyIndexSet<K, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
K: RefUnwindSafe,
S: RefUnwindSafe,
impl<K, S> UnwindSafe for NonEmptyIndexSet<K, S> where
K: UnwindSafe,
S: UnwindSafe,
K: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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<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> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
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>,