Struct eset::ESet

source ·
pub struct ESet<T: ReprEnum, const SEP: char = '|'>(/* private fields */);
Expand description

An enum set for a fieldless enum T.

Operators

  • !: bitwise not
  • |: bitwise or, or union
  • &: bitwise and, or intersection
  • ^: bitwise xor, or exclusive or
  • -: difference, a - b is equivalent to a ^ (a & b)
  • +: alias for union

Operators are not availble to T by default unless T implements Into<ESet>. See derive_eset.

If the enum implements FromStr, this type provides parsing from CSV like syntax with a given SEP. You can use a crate like strum for this type of functionality.

If serde is enabled, ths type serializes into a CSV like string in human readable formats and its integer flags representation in non-human-readable formats.

While this type is perfectly usable, the user should alias this type ASAP with a fixed SEP for better ergonomics.

type Csv<T> = ESet<T, ','>;

This struct does not maintain the invarient that all bits correspond to valid T, instead invalid bits are ignored during iteration and parsing. This makes operations like bitwise not and binary serialization safe to do.

Implementations§

source§

impl<T: ReprEnum, const S: char> ESet<T, S>

source

pub const NONE: Self = _

The empty ESet.

source

pub fn new(item: T) -> Self

Create a new Eset from an single enum.

source

pub fn new_flags<TIter>(item: impl IntoIterator<Item = TIter>) -> Selfwhere Self: FromIterator<TIter>,

Create a new Eset from an iterator of enums.

source

pub fn is_empty(&self) -> bool

Check if the ESet is empty.

source

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

Check if the ESet contains a specific enum.

source

pub fn insert(&mut self, item: T) -> &mut Self

mutate the ESet by inserting an enum.

source

pub fn remove(&mut self, item: T) -> &mut Self

mutate the ESet by removing an enum.

source

pub fn with(self, item: T) -> Self

Create a new ESet by inserting an enum.

source

pub fn without(self, item: T) -> Self

Create a new ESet by removing an enum.

source

pub const fn with_separator<const SEP: char>(self) -> ESet<T, SEP>

Convert a ESet into one with a different separator.

source

pub fn iter(&self) -> ESetIter<T, S>

Iterate over enums in the ESet.

Trait Implementations§

source§

impl<T: ReprEnum, R: Into<Self>, const S: char> Add<R> for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the + operator.
source§

fn add(self, rhs: R) -> Self::Output

Performs the + operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> AddAssign<R> for ESet<T, S>

source§

fn add_assign(&mut self, rhs: R)

Performs the += operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitAnd<R> for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: R) -> Self::Output

Performs the & operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitAndAssign<R> for ESet<T, S>

source§

fn bitand_assign(&mut self, rhs: R)

Performs the &= operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitOr<R> for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: R) -> Self::Output

Performs the | operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitOrAssign<R> for ESet<T, S>

source§

fn bitor_assign(&mut self, rhs: R)

Performs the |= operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitXor<R> for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, rhs: R) -> Self::Output

Performs the ^ operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> BitXorAssign<R> for ESet<T, S>

source§

fn bitxor_assign(&mut self, rhs: R)

Performs the ^= operation. Read more
source§

impl<T: Clone + ReprEnum, const SEP: char> Clone for ESet<T, SEP>where T::FlagsRepr: Clone,

source§

fn clone(&self) -> ESet<T, SEP>

Returns a copy 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, const S: char> Debug for ESet<T, S>where T: Debug + ReprEnum,

source§

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

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

impl<T: ReprEnum, const S: char> Default for ESet<T, S>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T, const S: char> Display for ESet<T, S>where T: Display + ReprEnum,

source§

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

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

impl<'t, T, const S: char> FromIterator<&'t T> for ESet<T, S>where T: 't + Copy + ReprEnum,

source§

fn from_iter<A: IntoIterator<Item = &'t T>>(iter: A) -> Self

Creates a value from an iterator. Read more
source§

impl<T: ReprEnum, const S: char> FromIterator<T> for ESet<T, S>

source§

fn from_iter<A: IntoIterator<Item = T>>(iter: A) -> Self

Creates a value from an iterator. Read more
source§

impl<T, const S: char> FromStr for ESet<T, S>where T: FromStr + ReprEnum,

§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<T: Hash + ReprEnum, const SEP: char> Hash for ESet<T, SEP>where T::FlagsRepr: Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: ReprEnum, const S: char> IntoIterator for &ESet<T, S>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = ESetIter<T, S>

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: ReprEnum, const S: char> IntoIterator for ESet<T, S>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = ESetIter<T, S>

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: ReprEnum, const S: char> Not for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl<T: ReprEnum, const S: char> PartialEq<ESet<T, S>> for ESet<T, S>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: ReprEnum, const S: char> PartialOrd<ESet<T, S>> for ESet<T, S>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

== mean equal > means contains, < means contained by, otherwise None

1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> Sub<R> for ESet<T, S>

§

type Output = ESet<T, '|'>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: R) -> Self::Output

Performs the - operation. Read more
source§

impl<T: ReprEnum, R: Into<Self>, const S: char> SubAssign<R> for ESet<T, S>

source§

fn sub_assign(&mut self, rhs: R)

Performs the -= operation. Read more
source§

impl<T: Copy + ReprEnum, const SEP: char> Copy for ESet<T, SEP>where T::FlagsRepr: Copy,

Auto Trait Implementations§

§

impl<T, const SEP: char> RefUnwindSafe for ESet<T, SEP>where <T as ReprEnum>::FlagsRepr: RefUnwindSafe,

§

impl<T, const SEP: char> Send for ESet<T, SEP>where <T as ReprEnum>::FlagsRepr: Send,

§

impl<T, const SEP: char> Sync for ESet<T, SEP>where <T as ReprEnum>::FlagsRepr: Sync,

§

impl<T, const SEP: char> Unpin for ESet<T, SEP>where <T as ReprEnum>::FlagsRepr: Unpin,

§

impl<T, const SEP: char> UnwindSafe for ESet<T, SEP>where <T as ReprEnum>::FlagsRepr: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.