NonEmptyIndexSet

Struct NonEmptyIndexSet 

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

Source

pub fn new(first: K) -> Self

Creates a set with a default hasher.

Source

pub fn with_capacity(first: K, capacity: usize) -> Self

Creates a set with a given capacity.

Source

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

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

Source§

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

Source

pub fn with_hasher(first: K, hash_builder: S) -> Self

Creates a set with a given hasher.

Source

pub fn with_capacity_and_hasher( first: K, capacity: usize, hash_builder: S, ) -> Self

Creates a set with a given capacity.

Source

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

Iterates over key-value paris of the set in an immutable way.

Source

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.

Source

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

Gets a stored key from the set.

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

Source

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

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.

Source

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

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.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

Source

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

pub fn get_first(&self) -> &K

Gets an immutable reference to the first element.

Source

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

Gets a mutable reference to the first element.

Source

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

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

Source

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

Gets a mutable reference to the rest indexed set 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 set.

Source

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

Source§

impl<K: Clone, S: Clone> Clone for NonEmptyIndexSet<K, S>

Source§

fn clone(&self) -> NonEmptyIndexSet<K, 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, S> Debug for NonEmptyIndexSet<K, S>
where K: Eq + Hash + Debug, S: BuildHasher,

Source§

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

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

impl<'de, K, S> Deserialize<'de> for NonEmptyIndexSet<K, S>
where K: Deserialize<'de> + Eq + Hash, 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, S> Extend<K> for NonEmptyIndexSet<K, S>
where K: Eq + Hash, S: BuildHasher,

Source§

fn extend<T: IntoIterator<Item = K>>(&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, S: BuildHasher> Into<IndexSet<K, S>> for NonEmptyIndexSet<K, S>

Source§

fn into(self) -> IndexSet<K, S>

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

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

Source§

type IntoIter = IntoIter<K>

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

type Item = K

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

fn eq(&self, other: &NonEmptyIndexSet<K, 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, H> Serialize for NonEmptyIndexSet<K, H>
where K: Serialize + Eq + Hash, 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, S> Eq for NonEmptyIndexSet<K, S>
where K: Hash + Eq, S: BuildHasher,

Auto Trait Implementations§

§

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

§

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

§

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,

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