Skip to main content

impl_flag_trait

Macro impl_flag_trait 

Source
macro_rules! impl_flag_trait {
    ($name:ident, $type:ty) => { ... };
}
Expand description

impl_flag_trait! - The Master Flag Factory.

This macro is a “High-Level Orchestrator.” It does three critical things:

  1. Defines the Schema: Creates a private-field struct with essential derives.
  2. Injects Utility: Calls the “Boilerplate Assassins” (new, default, from, value).
  3. Fulfills the Contract: Implements the Flag trait using direct bitwise masking.

§Logic Style: Masking

Unlike the index-based shifting (1 << i), this macro assumes the Value passed in is a pre-calculated mask. This is highly optimized for performance.

§Arguments

  • $name - The identifier for your new Type (e.g., NetworkFlags).
  • $type - The underlying integer width (e.g., u8, u16, u32, u64).