NESet

Struct NESet 

Source
pub struct NESet<T: Eq + Hash>(/* private fields */);
Expand description

Non-empty set type.

Implementations§

Source§

impl<T: Eq + Hash> NESet<T>

Source

pub fn new(head: T, tail: Vec<T>) -> Self

Creates a new NESet, ensuring at least one element is present.

Source

pub fn singleton(value: T) -> Self

Creates a new singleton NESet. Semantically equivalent to:

NESet::new(value, Vec::new());
Source

pub fn from(set: HashSet<T>) -> Result<Self, NonEmptyError>

Creates a new NESet from a HashSet. Returns an error if the set is empty.

Source

pub fn into_set(self) -> HashSet<T>

Extracts the underlying HashSet. This operation is zero-cost.

Source

pub fn len(&self) -> usize

Returns the size of the set.

Source

pub fn is_empty(&self) -> bool

A NESet is always non-empty.

Source

pub fn insert(&mut self, value: T) -> bool

Adds an element to the set. If the element is already present, it is not modified.

Source

pub fn remove(&mut self, value: &T) -> bool

Removes an element from the set. Returns true if the element was present.

Source

pub fn contains(&self, value: &T) -> bool

Checks if the set contains a value.

Trait Implementations§

Source§

impl<T: Clone + Eq + Hash> Clone for NESet<T>

Source§

fn clone(&self) -> NESet<T>

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<T: Debug + Eq + Hash> Debug for NESet<T>

Source§

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

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

impl<T: Eq + Hash> From<NESet<T>> for HashSet<T>

Source§

fn from(value: NESet<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Eq + Hash> From<T> for NESet<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Eq + Hash> IntoIterator for &'a NESet<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

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<T: Eq + Hash> IntoIterator for NESet<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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<T: PartialEq + Eq + Hash> PartialEq for NESet<T>

Source§

fn eq(&self, other: &NESet<T>) -> 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<T: Eq + Hash> TryFrom<HashSet<T>> for NESet<T>

Source§

type Error = NonEmptyError

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

fn try_from(set: HashSet<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: Eq + Eq + Hash> Eq for NESet<T>

Source§

impl<T: Eq + Hash> StructuralPartialEq for NESet<T>

Auto Trait Implementations§

§

impl<T> Freeze for NESet<T>

§

impl<T> RefUnwindSafe for NESet<T>
where T: RefUnwindSafe,

§

impl<T> Send for NESet<T>
where T: Send,

§

impl<T> Sync for NESet<T>
where T: Sync,

§

impl<T> Unpin for NESet<T>
where T: Unpin,

§

impl<T> UnwindSafe for NESet<T>
where T: 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<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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.