macro_rules! scope {
(
$(
$(#[$struct_meta:meta])*
$struct_vis:vis enum $struct_ident:ident {
$(
$(#[$field_meta:meta])*
$field_ident:ident = $($field_literal:literal)? $($field_idents:ident)&&*
),* $(,)?
}
)+
) => { ... };
}Expand description
Defines one or more bitmap-backed permission scope types.
The syntax resembles an enum declaration, but the macro generates a newtype
struct with associated constants and set-like operations. Each primitive flag
is declared with a numeric bit position, while aliases can be declared as a
combination of other flags with &&.
ยงExample
use snowfinch::scope;
scope! {
// Permissions for an example service.
pub enum Permissions {
// Permission to read data.
Read = 0,
// Permission to write data.
Write = 1,
// Read and write permissions.
ReadWrite = Read && Write,
}
}
let scope = Permissions::Read | Permissions::Write;
assert!(scope.contains(&Permissions::ReadWrite));
assert_eq!(Permissions::from_name("Read"), Some(Permissions::Read));The generated type implements Scope, core::fmt::Debug,
core::str::FromStr, bitwise set operators, and optional serde/sqlx
traits when those crate features are enabled.