forked from bitflags/bitflags
/
bitflags_trait.rs
53 lines (51 loc) · 2.19 KB
/
bitflags_trait.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use core as _core;
#[doc(hidden)]
pub trait ImplementedByBitFlagsMacro {}
/// A flags enum.
///
/// Manual implementations of this trait are not supported.
/// It should only be automatically implemented through the `bitflags!` macro.
pub trait BitFlags: ImplementedByBitFlagsMacro {
type Bits;
/// Returns an empty set of flags.
fn empty() -> Self;
/// Returns the set containing all flags.
fn all() -> Self;
/// Returns the raw value of the flags currently stored.
fn bits(&self) -> Self::Bits;
/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
fn from_bits(bits: Self::Bits) -> _core::option::Option<Self>
where Self: Sized;
/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
fn from_bits_truncate(bits: Self::Bits) -> Self;
/// Convert from underlying bit representation, preserving all
/// bits (even those not corresponding to a defined flag).
///
/// # Safety
///
/// The caller of the `bitflags!` macro can chose to allow or
/// disallow extra bits for their bitflags type.
///
/// The caller of `from_bits_unchecked()` has to ensure that
/// all bits correspond to a defined flag or that extra bits
/// are valid for this bitflags type.
unsafe fn from_bits_unchecked(bits: Self::Bits) -> Self;
/// Returns `true` if no flags are currently stored.
fn is_empty(&self) -> bool;
/// Returns `true` if all flags are currently set.
fn is_all(&self) -> bool;
/// Returns `true` if there are flags common to both `self` and `other`.
fn intersects(&self, other: Self) -> bool;
/// Returns `true` all of the flags in `other` are contained within `self`.
fn contains(&self, other: Self) -> bool;
/// Inserts the specified flags in-place.
fn insert(&mut self, other: Self);
/// Removes the specified flags in-place.
fn remove(&mut self, other: Self);
/// Toggles the specified flags in-place.
fn toggle(&mut self, other: Self);
/// Inserts or removes the specified flags depending on the passed value.
fn set(&mut self, other: Self, value: bool);
}