2 stable releases
1.0.1 | Sep 15, 2021 |
---|---|
1.0.0 | Sep 14, 2021 |
#600 in Concurrency
41 downloads per month
Used in dlt-tracing-subscriber
13KB
266 lines
Autoincrement
It is small library for implementing autoincremental values, such as IDs or others.
[dependencies]
autoincrement = "1"
Synchronous generator example
use autoincrement::prelude::*;
#[derive(Incremental, PartialEq, Eq, Debug)]
struct MyId(u32);
let mut generator = MyId::init();
assert_eq!(generator.pull(), MyId(1));
assert_eq!(generator.pull(), MyId(2));
assert_eq!(generator.pull(), MyId(3));
Set first value
use autoincrement::prelude::*;
#[derive(Incremental, PartialEq, Eq, Debug)]
struct MyId(u32);
let mut generator = MyId(20).init_from();
assert_eq!(generator.pull(), MyId(20));
assert_eq!(generator.pull(), MyId(21));
assert_eq!(generator.pull(), MyId(22));
Example with using thread-safe generator
[dependencies]
autoincrement = { version = "1", features = ["derive", "async"] }
use autoincrement::prelude::*;
#[derive(AsyncIncremental, PartialEq, Eq, Debug)]
struct MyId(u32);
let generator = MyId::init(); // does not need to be mutable
assert_eq!(generator.pull(), MyId(1));
assert_eq!(generator.pull(), MyId(2));
assert_eq!(generator.pull(), MyId(3));
Dependencies
~0–285KB