Skip to main content

ExampleFlags

Struct ExampleFlags 

Source
pub struct ExampleFlags(/* private fields */)
where
    u32: BitsPrimitive;
Expand description

A example bitflag

Implementations§

Source§

impl ExampleFlags

Source

pub const Flag1: Self

Source

pub const Flag2: Self

Source

pub const Flag3: Self

Source

pub const Flag4: Self

Source

pub const Flag5: Self

Source

pub const Flag6: Self

Source

pub const Flag7: Self

Source

pub const Flag8: Self

Source

pub const Flag9: Self

Source

pub const Flag10: Self

Source

pub const Flag11: Self

Source

pub const Flag12: Self

Source§

impl ExampleFlags

Source

pub const fn bits(&self) -> u32

Return the underlying bits of this bitflag.

Source

pub const fn from_bits(bits: u32) -> Option<Self>

Converts from a bits value. Returning None is any unknown bits are set.

Source

pub const fn from_bits_truncate(bits: u32) -> Self

Convert from bits value, unsetting any unknown bits.

Source

pub const fn from_bits_retain(bits: u32) -> Self

Convert from bits value exactly.

Source

pub fn from_flag_name(name: &str) -> Option<Self>

Convert from a flag name.

Source

pub const fn empty() -> Self

Construct a flags value with all bits unset.

Source

pub const fn is_empty(&self) -> bool

Returns true if the flag value has all bits unset.

Source

pub const fn all_bits() -> Self

Returns a flag value that contains all value.

This will include bits that do not have any flags/meaning. Use all if you want only the specified flags set.

Source

pub const fn is_all_bits(&self) -> bool

Returns true if the flag value contains all value bits set.

This will check for all bits. Use is_all if you want to check for all specified flags.

Source

pub const fn all() -> Self

Construct a flag value with all known flags set.

This will only set the flags specified as associated constant and the defined extra valid bits.

Source

pub const fn is_all(&self) -> bool

Returns true if the flag value contais all known flags.

Source

pub const fn all_named() -> Self

Construct a flag value with all known named flags set.

This will only set the flags specified as associated constant without the defined extra valid bits.

Source

pub const fn is_all_named(&self) -> bool

Returns true if the flag value contais all known named flags.

Source

pub const fn contains_unknown_bits(&self) -> bool

Returns true if there are any unknown bits set in the flag value.

Source

pub const fn contains_unnamed_bits(&self) -> bool

Returns true if there are any unnamed known bits set in the flag value.

Source

pub const fn truncated(&self) -> Self

Returns a bit flag with unknown bits removed from the original value.

Source

pub fn truncate(&mut self)

Removes unknown bits from the flag value.

Source

pub const fn intersects(&self, other: Self) -> bool

Returns true if this flag value intersects with any value in other.

This is equivalent to (self & other) != Self::empty()

Source

pub const fn contains(&self, other: Self) -> bool

Returns true if this flag value contains all values of other.

This is equivalent to (self & other) == other

Source

pub const fn not(self) -> Self

Returns the bitwise NOT of the flag.

This function does not truncate unused bits (bits that do not have any flags/meaning). Use complement if you want that the result to be truncated in one call.

Source

pub const fn and(self, other: Self) -> Self

Returns the bitwise AND of the flag.

Source

pub const fn or(self, other: Self) -> Self

Returns the bitwise OR of the flag with other.

Source

pub const fn xor(self, other: Self) -> Self

Returns the bitwise XOR of the flag with other.

Source

pub const fn intersection(self, other: Self) -> Self

Returns the intersection from this value with other.

Source

pub const fn union(self, other: Self) -> Self

Returns the union from this value with other.

Source

pub const fn difference(self, other: Self) -> Self

Returns the difference from this value with other.

In other words, returns the intersection of this value with the negation of other.

This method is not equivalent to self & !other when other has unknown bits set. difference won’t truncate other, but the ! operator will.

Source

pub const fn symmetric_difference(self, other: Self) -> Self

Returns the symmetric difference from this value with other.

Source

pub const fn complement(self) -> Self

Returns the complement of the value.

This is very similar to the not, but truncates non used bits.

Source

pub fn set(&mut self, other: Self)

Set the flags in other in the value.

Source

pub fn unset(&mut self, other: Self)

Unset the flags bits in other in the value.

Source

pub fn toggle(&mut self, other: Self)

Toggle the flags in other in the value.

Source

pub fn clear(&mut self)

Resets the flags to a empty state.

Source§

impl ExampleFlags

Source

pub const fn iter(&self) -> Iter<Self>

Yield a set of contained flags values.

Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.

Source

pub const fn iter_names(&self) -> IterNames<Self>

Yield a set of contained named flags values.

This method is like iter, except only yields bits in contained named flags. Any unknown bits, or bits not corresponding to a contained flag will not be yielded.

Trait Implementations§

Source§

impl Binary for ExampleFlags

Source§

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

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

impl BitAnd for ExampleFlags

Source§

type Output = ExampleFlags

The resulting type after applying the & operator.
Source§

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

Performs the & operation. Read more
Source§

impl BitAndAssign for ExampleFlags

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for ExampleFlags

Source§

type Output = ExampleFlags

The resulting type after applying the | operator.
Source§

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

Performs the | operation. Read more
Source§

impl BitOrAssign for ExampleFlags

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitXor for ExampleFlags

Source§

type Output = ExampleFlags

The resulting type after applying the ^ operator.
Source§

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

Performs the ^ operation. Read more
Source§

impl BitXorAssign for ExampleFlags

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for ExampleFlags

Source§

fn clone(&self) -> ExampleFlags

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ExampleFlags

Source§

impl Debug for ExampleFlags

Source§

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

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

impl Eq for ExampleFlags

Source§

impl Extend<ExampleFlags> for ExampleFlags

Source§

fn extend<T: IntoIterator<Item = Self>>(&mut self, iter: T)

Set all flags of iter to self

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 Flags for ExampleFlags

Source§

const NAMED_FLAGS: &'static [(&'static str, ExampleFlags)]

The set of named defined flags.
Source§

const RESERVED_BITS: u32

All reserved bits values for the flags. Read more
Source§

type Bits = u32

The underlying bits type.
Source§

fn bits(&self) -> Self::Bits

Return the underlying bits value. Read more
Source§

fn from_bits_retain(bits: Self::Bits) -> Self

Convert from bits value exactly.
Source§

fn from_bits(bits: Self::Bits) -> Option<Self>

Converts from a bits value. Returning None is any unknown bits are set.
Source§

fn from_bits_truncate(bits: Self::Bits) -> Self

Convert from bits value, unsetting any unknown bits.
Source§

fn from_flag_name(name: &str) -> Option<Self>

Convert from a flag name.
Source§

fn from_name(name: &str) -> Option<Self>

Get a flags value with the bits of a flag with the given name set. Read more
Source§

fn empty() -> Self

Construct a flags value with all bits unset.
Source§

fn is_empty(&self) -> bool

Returns true if the flags value has all bits unset.
Source§

fn all_bits() -> Self

Returns a flags value that contains all value. Read more
Source§

fn is_all_bits(&self) -> bool

Returns true if the bitflag contains all value bits set. Read more
Source§

fn all() -> Self

Construct a flags value with all known flags set. Read more
Source§

fn is_all(&self) -> bool

Whether all known bits in this flags value are set.
Source§

fn all_named() -> Self

Construct a flags value with all known named flags set. Read more
Source§

fn is_all_named(&self) -> bool

Returns true if the flags value contais all known named flags.
Source§

fn contains_unknown_bits(&self) -> bool

Returns true if there are any unknown bits set in the flags value.
Source§

fn contains_unnamed_bits(&self) -> bool

Returns true if there are any unnamed known bits set in the flags value.
Source§

fn truncated(&self) -> Self

Returns a flags value with unknown bits removed from the original flags value.
Source§

fn intersects(&self, other: Self) -> bool
where Self: Sized,

Returns true if this flags value intersects with any value in other. Read more
Source§

fn contains(&self, other: Self) -> bool
where Self: Sized,

Returns true if this flags value contains all values of other. Read more
Source§

fn truncate(&mut self)
where Self: Sized,

Remove any unknown bits from the flags.
Source§

fn intersection(self, other: Self) -> Self

Returns the intersection from this flags value with other.
Source§

fn union(self, other: Self) -> Self

Returns the union from this flags value with other.
Source§

fn difference(self, other: Self) -> Self

Returns the difference from this flags value with other. Read more
Source§

fn symmetric_difference(self, other: Self) -> Self

Returns the symmetric difference from this flags value with other..
Source§

fn complement(self) -> Self

Returns the complement of the flags value. Read more
Source§

fn set(&mut self, other: Self)
where Self: Sized,

Set the flags in other in the value.
Source§

fn unset(&mut self, other: Self)
where Self: Sized,

Unset the flags bits in other in the value. Read more
Source§

fn toggle(&mut self, other: Self)
where Self: Sized,

Toggle the flags in other in the value.
Source§

fn clear(&mut self)

Resets the flags value to a empty state.
Source§

fn iter(&self) -> Iter<Self>

Yield a set of contained flags values. Read more
Source§

fn iter_names(&self) -> IterNames<Self>

Yield a set of contained named flags values. Read more
Source§

impl From<ExampleFlags> for u32

Source§

fn from(val: ExampleFlags) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for ExampleFlags

Source§

fn from(val: u32) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<ExampleFlags> for ExampleFlags

Source§

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

Create a ExampleFlags from a iterator of flags.

Source§

impl FromStr for ExampleFlags

Source§

type Err = ParseError

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

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

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

impl Hash for ExampleFlags

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 IntoIterator for &ExampleFlags

Source§

type Item = ExampleFlags

The type of the elements being iterated over.
Source§

type IntoIter = Iter<ExampleFlags>

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 IntoIterator for ExampleFlags

Source§

type Item = ExampleFlags

The type of the elements being iterated over.
Source§

type IntoIter = Iter<ExampleFlags>

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 LowerHex for ExampleFlags

Source§

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

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

impl Not for ExampleFlags

Source§

type Output = ExampleFlags

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl Octal for ExampleFlags

Source§

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

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

impl Ord for ExampleFlags

Source§

fn cmp(&self, other: &ExampleFlags) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ExampleFlags

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialOrd for ExampleFlags

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for ExampleFlags

Source§

impl Sub for ExampleFlags

Source§

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

The intersection of a source flag with the complement of a target flags value

Source§

type Output = ExampleFlags

The resulting type after applying the - operator.
Source§

impl SubAssign for ExampleFlags

Source§

fn sub_assign(&mut self, rhs: Self)

The intersection of a source flag with the complement of a target flags value

Source§

impl UpperHex for ExampleFlags

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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