Macro blazemap::define_plain_id

source ·
macro_rules! define_plain_id {
    (
        $(#[$attrs:meta])*
        $vis:vis
        struct $new_type:ident
        $(; Derive: {$($to_derive_sn:ident),+ $(,)?} )?
        $(;)?
    ) => { ... };
}
Expand description

Creates a new type based on incrementally generated usize instances that can be used as a key for blazemap collections.

This macro supports optional inference of standard traits using the following syntax:

  • Derive — derives traits in the same way as for the serial number assigned when creating a new instance of the type. Because methods inferred by this option do not require additional locking on synchronization primitives, they do not incur any additional overhead compared to methods inferred for plain usize. This method supports inference of the following traits:
    • PartialOrd (mutually exclusive with Ord)
    • Ord (also derives PartialOrd, so mutually exclusive with PartialOrd)
    • Serialize (with serde feature only)

§Example

use blazemap::prelude::{BlazeMap, define_plain_id};

define_plain_id! {
    pub struct Id;
    Derive: {       // Optional section
        Ord
    };
}

let key_1 = Id::new();
let key_2 = Id::new();
let key_3 = Id::new();

let mut map = BlazeMap::new();
map.insert(key_2, "2");
map.insert(key_1, "1");
map.insert(key_3, "3");

assert_eq!(format!("{map:?}"), r#"{0: "1", 1: "2", 2: "3"}"#)