3 releases

0.1.2 Jul 6, 2024
0.1.1 Jul 4, 2024
0.1.0 Jun 26, 2024

#678 in Data structures

Download history 13/week @ 2024-07-28 1/week @ 2024-08-04 7/week @ 2024-08-11 2/week @ 2024-08-18 23/week @ 2024-08-25 10/week @ 2024-09-01 27/week @ 2024-09-08 64/week @ 2024-09-15 44/week @ 2024-09-22 63/week @ 2024-09-29 7/week @ 2024-10-06 13/week @ 2024-10-13 12/week @ 2024-10-20 10/week @ 2024-10-27 59/week @ 2024-11-03

95 downloads per month
Used in tree-ds

MIT license

14KB
161 lines

Sequential_Gen

Build Status

Crates.io Docs.rs License: MIT

A simple crate to generate sequential ids in Rust. This crate is useful when you need to generate sequential ids for your data structures.

I recently needed to generate sequential ids for a tree data structure that I was working on, and I couldn't find a crate that provided this functionality with no_std capabilities. So I decided to create this crate to fill that gap.

Usage

Add the following to your Cargo.toml file:

[dependencies]
sequential_gen = "0.1"

Generating Sequential Ids

To ensure that the generated ids are unique, we need to ensure only a single instance of the Generator trait is available in the program. Once you have your Generator instance, you can use the generate method to generate sequential ids.

extern crate lazy_static;

use lazy_static::lazy_static;
use sequential_gen::prelude::*;

lazy_static! {
    static ref GENERATOR: SimpleGenerator<usize> = SimpleGenerator::new(1usize);
}

fn main() {
	let id = GENERATOR.generate();
	// Use your ID
}

Note: You can also create your own generator by implementing the Generator trait if you need more control over the generation process or if the provided generators do not meet your requirements.

no_std Support

The crate is no_std compatible, but you need to disable the default features in your Cargo.toml file. You then need to enable the no_std feature:

[dependencies]
sequential_gen = { version = "0.1", default-features = false, features = ["no_std"] }

Note: When working in a no_std environment, you are confined to using the SimpleGenerator struct. In most cases this will suffice. The other generators require the std library.

The usage of the crate remains the same.

License

This project is licensed under the MIT license.

Dependencies

~455–720KB
~14K SLoC