Crate rate_limit_macro
source ·Expand description
This crate provides “rate_limit_macro” procedural macro.
Usage:
Here is code example:
use rate_limit_macro::rate_limit;
let mut called_times = 0;
for _ in 0..10 { rate_limit!(rate = 5, interval = 1, { called_times += 1; }); }
// Only 5 calls should have been allowed due to rate limiting. assert_eq!(called_times, 5);
Notes:
- this macro is lockless, the rate limiting may not be 100% accurate.
Macros
- Rate-limits the execution of a block of code.