devela::data

Macro id_seq

Source
macro_rules! id_seq {
    (
        // $name: the name of the sequential ID generator. E.g. AppId1.
        // $prim: the underlying primitive type. E.g. u64.
        $name:ident,
        $prim:ty
    ) => { ... };
    ($name:ident, $tname:ty, $static:ident, $prim:ty, $atomic:ident) => { ... };
}
Expand description

A macro for constructing a unique sequential identifier generator.

It generates the necessary static instances dynamically.

ยงExample

id_seq![AppId1, u8];

assert_eq![AppId1::generated_ids(), 0];
assert_eq![AppId1::remaining_ids(), u8::MAX - 1];

assert_eq![AppId1::new().unwrap().value(), 1];
assert_eq![AppId1::new_unchecked().value(), 2];

// generate all remaining ids.
for _ in 2..u8::MAX {
    let _ = AppId1::new_fast_unchecked();
}
assert_eq![AppId1::new_fast(), None];

See also the id_seq example.