autoincrement

Crates.ioautoincrement
lib.rsautoincrement
version1.0.1
sourcesrc
created_at2021-09-14 18:38:35.994006
updated_at2021-09-15 07:29:53.010984
descriptionAutoincrement wrapper for different purposes
homepage
repositoryhttps://github.com/amv-dev/autoincrement
max_upload_size
id451328
size23,917
Dmitry (amv-dev)

documentation

README

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));
Commit count: 7

cargo fmt