#proc-macro #macro #rust

macro global-id-creator-macro

A procedural macro library for generating constants

2 releases

0.1.1 Nov 17, 2024
0.1.0 Sep 29, 2024

#418 in Procedural macros

Download history 85/week @ 2024-09-23 116/week @ 2024-09-30 8/week @ 2024-10-07 2/week @ 2024-10-14 5/week @ 2024-11-04 47/week @ 2024-11-11 70/week @ 2024-11-18 1/week @ 2024-11-25 13/week @ 2024-12-09

131 downloads per month

MIT license

5KB

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

Dependencies

~220–660KB
~16K SLoC