commit | 2e87f0c882d36b202d6f2908d5b35b893d97766d | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Jun 22 17:08:06 2023 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Thu Jun 22 17:08:06 2023 +0000 |
tree | 680ec0b7c7385389bf019efd940a1690c6aac350 | |
parent | a6ca87571a22068a447f4c963ec5027eb4924c5e [diff] | |
parent | 4cb5dac10a9ca8a0c9b78ea24f0f23e7972576e2 [diff] |
Snap for 10363732 from 4cb5dac10a9ca8a0c9b78ea24f0f23e7972576e2 to emu-33-release Change-Id: Id126fea370d93f0e27ae3c893cc1556b9014fc39
A Rust macro to generate structures which behave like a set of bitflags
Add this to your Cargo.toml
:
[dependencies] bitflags = "2.3.2"
and this to your source code:
use bitflags::bitflags;
Generate a flags structure:
use bitflags::bitflags; // The `bitflags!` macro generates `struct`s that manage a set of flags. bitflags! { #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] struct Flags: u32 { const A = 0b00000001; const B = 0b00000010; const C = 0b00000100; const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits(); } } fn main() { let e1 = Flags::A | Flags::C; let e2 = Flags::B | Flags::C; assert_eq!((e1 | e2), Flags::ABC); // union assert_eq!((e1 & e2), Flags::C); // intersection assert_eq!((e1 - e2), Flags::A); // set difference assert_eq!(!e2, Flags::A); // set complement }
The minimum supported Rust version is documented in the Cargo.toml
file. This may be bumped in minor releases as necessary.