Skip to main content

bitflags2_derive/
lib.rs

1use proc_macro::TokenStream;
2use syn::{ItemEnum, parse_macro_input};
3
4mod codegen;
5mod model;
6mod parse;
7
8/// Expands an enum into a compact bitflag type.
9///
10/// The `#[flag]` attributes on variants are helper markers consumed by this
11/// attribute macro. They are intentionally not exported as standalone macros,
12/// so using `#[flag]` without `#[flags]` fails at compile time.
13#[proc_macro_attribute]
14pub fn flags(_attr: TokenStream, item: TokenStream) -> TokenStream {
15    let input = parse_macro_input!(item as ItemEnum);
16
17    match parse::parse_flags(input) {
18        Ok(flags) => codegen::generate(flags).into(),
19        Err(error) => error.to_compile_error().into(),
20    }
21}