#auto-increment #derive #values #id #incremental

macro autoincrement_derive

Derive macros for autoincrement crate

2 stable releases

1.0.1 Sep 15, 2021
1.0.0 Sep 14, 2021

#292 in #id

Download history 6/week @ 2024-07-20 17/week @ 2024-07-27 86/week @ 2024-08-03 19/week @ 2024-08-10 27/week @ 2024-08-17 17/week @ 2024-08-24 53/week @ 2024-08-31 42/week @ 2024-09-07 45/week @ 2024-09-14 14/week @ 2024-09-21 15/week @ 2024-09-28 14/week @ 2024-10-05 25/week @ 2024-10-12 29/week @ 2024-10-19 74/week @ 2024-10-26 264/week @ 2024-11-02

395 downloads per month
Used in autoincrement

Apache-2.0

7KB
125 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

~1.5MB
~37K SLoC