Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/bitflags/examples/custom_derive.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 3 use std::str; 4 5 use 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)] 11 pub struct ManualFlags(u32); 12 13 // Next: use `impl Flags` instead of `struct Flags` 14 bitflags! { 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 23 fn main() {}