global-id-creator-macro

Crates.ioglobal-id-creator-macro
lib.rsglobal-id-creator-macro
version0.1.1
sourcesrc
created_at2024-09-29 19:16:33.408666
updated_at2024-11-17 15:41:24.150002
descriptionA procedural macro library for generating constants
homepage
repository
max_upload_size
id1391087
size5,254
(xwitch1707)

documentation

README

GLOBAL ID CREATOR

this is a small procedural macro which can be use in global to create a list of constant with the id is u8. increace by 1 for each constant created

use global_id_creator_macro::ntl_create_global_id;

pub enum Global {
    Id(u8)
}

ntl_create_global_id!(Global, CONST_A, CONST_B, CONST_C, CONST_D, CONST_E);

fn main() {
    println!("CONST_A = {:?}", CONST_A);
    println!("CONST_B = {:?}", CONST_B);
    println!("CONST_C = {:?}", CONST_C);
    println!("CONST_D = {:?}", CONST_D);
    println!("CONST_E = {:?}", CONST_E);
}

output:

CONST_A = Id(100)
CONST_B = Id(101)
CONST_C = Id(102)
CONST_D = Id(103)
CONST_E = Id(104)

the macro will be expanded like this:

pub const CONST_A: Global = Global::Id(100);
pub const CONST_A: Global = Global::Id(101);
pub const CONST_A: Global = Global::Id(102);
pub const CONST_A: Global = Global::Id(103);
pub const CONST_A: Global = Global::Id(104);

This crate is just use for my personal project, so it maybe not fit which your need

Commit count: 0

cargo fmt