macro_rules! flag_ro { ($name:ident, $pos:expr) => { ... }; ($name:ident, $full_name:ident, $pos:expr) => { ... }; }
Expand description
Create read-only flag.
It accepts a name argument, optional full name argument and a number, which indicates the bit number with required flag.
Later, the given flag can be accessed either by short or full name in a form of a normal function.
It will work only if it’s put in a structure implementation where integer number with bit fields can be accessed with ‘self.0’.
ReadOnly flags accepts ‘self.0’ to be of any integer type.
§Example
#[macro_use]
extern crate altbitflags;
struct Something(i64);
impl Something {
flag_ro!(present, 0);
flag_ro!(tx, 1);
flag_ro!(e, extended, 2);
// It is okay to define different functions for a single bit:
flag_ro!(some, 3);
flag_ro!(some_bit, 3);
}
fn main() {
let mut something = Something(0);
if (something.present()) { /* ... */ }
if (something.tx()) { /* ... */ }
// These do the same thing:
if (something.e()) { /* ... */ }
if (something.extended()) { /* ... */ }
}