mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-06 11:18:19 +02:00
We currently are using a fake bitflags 2, derived from bitflags 1. More and more crates are using it, and we're at a sweet spot where flipping things around makes sense: using a fake bitflags 1, derived from bitflags 2. Differential Revision: https://phabricator.services.mozilla.com/D189316
23 lines
644 B
Rust
23 lines
644 B
Rust
//! An example of implementing the `BitFlags` trait manually for a flags type.
|
|
|
|
use std::str;
|
|
|
|
use bitflags::bitflags;
|
|
|
|
// Define a flags type outside of the `bitflags` macro as a newtype
|
|
// It can accept custom derives for libaries `bitflags` doesn't support natively
|
|
#[derive(zerocopy::AsBytes, zerocopy::FromBytes)]
|
|
#[repr(transparent)]
|
|
pub struct ManualFlags(u32);
|
|
|
|
// Next: use `impl Flags` instead of `struct Flags`
|
|
bitflags! {
|
|
impl ManualFlags: u32 {
|
|
const A = 0b00000001;
|
|
const B = 0b00000010;
|
|
const C = 0b00000100;
|
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
|
}
|
|
}
|
|
|
|
fn main() {}
|