autoincrement

Autoincrement wrapper for different purposes

2 stable releases

1.0.1 Sep 15, 2021
1.0.0 Sep 14, 2021

#637 in Concurrency

Download history 5/week @ 2024-07-20 13/week @ 2024-07-27 83/week @ 2024-08-03 16/week @ 2024-08-10 24/week @ 2024-08-17 14/week @ 2024-08-24 50/week @ 2024-08-31 43/week @ 2024-09-07 41/week @ 2024-09-14 14/week @ 2024-09-21 11/week @ 2024-09-28 13/week @ 2024-10-05 22/week @ 2024-10-12 24/week @ 2024-10-19 71/week @ 2024-10-26 260/week @ 2024-11-02

380 downloads per month
Used in dlt-tracing-subscriber

Apache-2.0

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–290KB