2 unstable releases

0.2.0 Apr 2, 2023
0.1.0 May 17, 2022

#1858 in Procedural macros

Download history 33/week @ 2024-03-11 30/week @ 2024-03-18 15/week @ 2024-03-25 68/week @ 2024-04-01 98/week @ 2024-04-08 28/week @ 2024-04-15 23/week @ 2024-04-22 40/week @ 2024-04-29 38/week @ 2024-05-06 10/week @ 2024-05-13 39/week @ 2024-05-20 19/week @ 2024-05-27 102/week @ 2024-06-03 55/week @ 2024-06-10 45/week @ 2024-06-17 21/week @ 2024-06-24

225 downloads per month

MIT/Apache

8KB
80 lines

Counting Macros

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.

Example

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);

Warning

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.


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~280–730KB
~17K SLoC