Crates.io | counting-macros |
lib.rs | counting-macros |
version | 0.2.0 |
source | src |
created_at | 2022-05-17 05:59:15.303 |
updated_at | 2023-04-02 21:25:22.888186 |
description | Stateful numeric incrementing macros |
homepage | |
repository | https://github.com/MisterEggnog/counting-macro-rs |
max_upload_size | |
id | 588158 |
size | 19,818 |
This library adds macro to get compile time counters. It uses procedural macros to implement state between macro invocations.
There are a few places this may be useful. Perhaps if you were defining a series of constant variables that you needed to increment for each variable. Of course in that situation it may make more sense to just build those values at runtime or using some kind of build script.
use counting_macros::*;
counter_create!(counter);
let nums = [counter_incr!(counter), counter_incr!(counter),
counter_incr!(counter)];
assert_eq!(nums, [0, 1, 2]);
counter_set!(counter, -5);
let nums = [counter_incr!(counter), counter_peek!(counter),
counter_incr!(counter)];
assert_eq!(nums, [-5, -4, -4]);
counter_next!(counter);
assert_eq!(counter_peek!(counter), -2);
I'm not certain about the stability or safety of this, so I would not recomend this for use in serious projects.
Additionally there is currently there is no error handling beyond unwraps.