Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
/ autoincrement Public archive

Small library for implementing autoincremental values, such as IDs or others

License

Notifications You must be signed in to change notification settings

amv-dev/autoincrement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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));

About

Small library for implementing autoincremental values, such as IDs or others

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages