Trait bitflags::Flags

source ·
pub trait Flags: Sized + 'static {
    type Bits: Bits;

    const FLAGS: &'static [Flag<Self>];
Show 22 methods // Required methods fn bits(&self) -> Self::Bits; fn from_bits_retain(bits: Self::Bits) -> Self; // Provided methods fn empty() -> Self { ... } fn all() -> Self { ... } fn from_bits(bits: Self::Bits) -> Option<Self> { ... } fn from_bits_truncate(bits: Self::Bits) -> Self { ... } fn from_name(name: &str) -> Option<Self> { ... } fn iter(&self) -> Iter<Self> { ... } fn iter_names(&self) -> IterNames<Self> { ... } fn is_empty(&self) -> bool { ... } fn is_all(&self) -> bool { ... } fn intersects(&self, other: Self) -> bool where Self: Sized { ... } fn contains(&self, other: Self) -> bool where Self: Sized { ... } fn insert(&mut self, other: Self) where Self: Sized { ... } fn remove(&mut self, other: Self) where Self: Sized { ... } fn toggle(&mut self, other: Self) where Self: Sized { ... } fn set(&mut self, other: Self, value: bool) where Self: Sized { ... } fn intersection(self, other: Self) -> Self { ... } fn union(self, other: Self) -> Self { ... } fn difference(self, other: Self) -> Self { ... } fn symmetric_difference(self, other: Self) -> Self { ... } fn complement(self) -> Self { ... }
}
Expand description

A set of flags.

This trait is automatically implemented for flags types defined using the bitflags! macro. It can also be implemented manually for custom flags types.

Required Associated Types§

source

type Bits: Bits

The underlying storage type.

Required Associated Constants§

source

const FLAGS: &'static [Flag<Self>]

The set of available flags and their names.

Required Methods§

source

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

Returns the raw value of the flags currently stored.

source

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

Convert from underlying bit representation, preserving all bits (even those not corresponding to a defined flag).

Provided Methods§

source

fn empty() -> Self

Returns an empty set of flags.

source

fn all() -> Self

Returns the set containing all flags.

source

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

Convert from underlying bit representation, unless that representation contains bits that do not correspond to a flag.

Note that each multi-bit flag is treated as a unit for this comparison.

source

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

Convert from underlying bit representation, dropping any bits that do not correspond to flags.

Note that each multi-bit flag is treated as a unit for this comparison.

source

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

Get the flag for a particular name.

source

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

Iterate over enabled flag values.

source

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

Iterate over the raw names and bits for enabled flag values.

source

fn is_empty(&self) -> bool

Returns true if no flags are currently stored.

source

fn is_all(&self) -> bool

Returns true if all flags are currently set.

source

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

Returns true if there are flags common to both self and other.

source

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

Returns true if all of the flags in other are contained within self.

source

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

Inserts the specified flags in-place.

source

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

Removes the specified flags in-place.

source

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

Toggles the specified flags in-place.

source

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

Inserts or removes the specified flags depending on the passed value.

source

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

Returns the intersection between the flags in self and other.

Specifically, the returned set contains only the flags which are present in both self and other.

source

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

Returns the union of between the flags in self and other.

Specifically, the returned set contains all flags which are present in either self or other, including any which are present in both (see Self::symmetric_difference if that is undesirable).

source

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

Returns the difference between the flags in self and other.

Specifically, the returned set contains all flags present in self, except for the ones present in other.

It is also conceptually equivalent to the “bit-clear” operation: flags & !other (and this syntax is also supported).

source

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

Returns the symmetric difference between the flags in self and other.

Specifically, the returned set contains the flags present which are present in self or other, but that are not present in both. Equivalently, it contains the flags present in exactly one of the sets self and other.

source

fn complement(self) -> Self

Returns the complement of this set of flags.

Specifically, the returned set contains all the flags which are not set in self, but which are allowed for this type.

Implementors§

source§

impl Flags for Flags

source§

const FLAGS: &'static [Flag<Flags>] = _

§

type Bits = u32