[][src]Struct non_empty_collections::index_set::NonEmptyIndexSet

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

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]

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

impl<K, S> NonEmptyIndexSet<K, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

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]

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]

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]

Gets a stored key from the set.

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 set.

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

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]

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]

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, S: BuildHasher> Into<IndexSet<K, S>> for NonEmptyIndexSet<K, S>[src]

impl<K, S> Extend<K> for NonEmptyIndexSet<K, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

impl<K: Clone, S: Clone> Clone for NonEmptyIndexSet<K, S>[src]

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

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

type IntoIter = IntoIter<K>

Which kind of iterator are we turning this into?

type Item = K

The type of the elements being iterated over.

impl<K, S1, S2> PartialEq<NonEmptyIndexSet<K, S1>> for NonEmptyIndexSet<K, S2> where
    K: Hash + Eq,
    S1: BuildHasher,
    S2: BuildHasher
[src]

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

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

impl<'de, K, S> Deserialize<'de> for NonEmptyIndexSet<K, S> where
    K: Deserialize<'de>,
    K: Eq + Hash,
    S: BuildHasher + Default
[src]

Auto Trait Implementations

impl<K, S> Send for NonEmptyIndexSet<K, S> where
    K: Send,
    S: Send

impl<K, S> Sync for NonEmptyIndexSet<K, S> where
    K: Sync,
    S: Sync

impl<K, S> Unpin for NonEmptyIndexSet<K, S> where
    K: Unpin,
    S: Unpin

impl<K, S> UnwindSafe for NonEmptyIndexSet<K, S> where
    K: UnwindSafe,
    S: UnwindSafe

impl<K, S> RefUnwindSafe for NonEmptyIndexSet<K, S> where
    K: RefUnwindSafe,
    S: RefUnwindSafe

Blanket Implementations

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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, 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> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<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]