Crates.io | autoincrement |
lib.rs | autoincrement |
version | 1.0.1 |
source | src |
created_at | 2021-09-14 18:38:35.994006 |
updated_at | 2021-09-15 07:29:53.010984 |
description | Autoincrement wrapper for different purposes |
homepage | |
repository | https://github.com/amv-dev/autoincrement |
max_upload_size | |
id | 451328 |
size | 23,917 |
It is small library for implementing autoincremental values, such as IDs or others.
[dependencies]
autoincrement = "1"
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));
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));
[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));