interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / bitflags / examples / custom_derive.rs

23 lines · 691 bytes Raw Blame History
1//! An example of implementing the `BitFlags` trait manually for a flags type.
2
3use std::str;
4
5use bitflags::bitflags;
6
7// Define a flags type outside of the `bitflags` macro as a newtype
8// It can accept custom derives for libraries `bitflags` doesn't support natively
9#[derive(zerocopy::IntoBytes, zerocopy::FromBytes, zerocopy::KnownLayout, zerocopy::Immutable)]
10#[repr(transparent)]
11pub struct ManualFlags(u32);
12
13// Next: use `impl Flags` instead of `struct Flags`
14bitflags! {
15 impl ManualFlags: u32 {
16 const A = 0b00000001;
17 const B = 0b00000010;
18 const C = 0b00000100;
19 const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
20 }
21}
22
23fn main() {}