Crate unique_id
A trait and implementations for unique ID generators.
This crate provides four simple traits, starting with Generator. This will return successive unique identifiers, the
only requirement of an identifier being that it implements PartialEq.
Each implemented generator is in its own feature, by default all of which are included.
- Generator
RandomGenerator, in featurerandom, provides a random number scheme returningu128values. Depends on the uuid crate. - Generator
SequenceGenerator, in featuresequence, provides monotonically increasing u64 values in a thread safe manner. Depends on the atomic_refcell and lazy_static crates. - Generator
StringGenerator, in featurestring, provides random string values. Depends on the blob-uuid crate.
Example
The following shows an example of the StringGenerator implementation.
use Generator;
use StringGenerator;
let gen = default;
let mut last = gen.next_id;
for _ in 1..100_000
Benchmarks
The cargo bench command will run a comparison benchmark to show the relative performance of all generators. This
benchmark is in benches/compare.cs and uses Criterion for report generation.
)
; ; ; ;
)
)
)
)
)
)
)
)
)
)
)
)
The output can be found in target/criterion/report/index.html.
Changes
Version 0.1.4
- Updated dependencies for
uuidandblob-uuidvia dependabot. - Removed
PhantomDatain generator structures.
Version 0.1.3
- Moved module-specific unit tests into a combined
tests/unique.rs. - Renamed
integertosequencein benchmarks. - Added more to the documentation.
Version 0.1.2
- Added new
RandomGeneratorimplementation. - Put each implementation into its own feature.
- Added
#[inline]to some functions.
Version 0.1.1
- Added trait
GeneratorFromSeedand implementation forSequenceGenerator. - Added a benchmark to compare the two current implementations.
Version 0.1.0
- Simple traits
Generator,GeneratorWithInvalid, andGeneratorFromStr. StringGeneratorusing UUIDsSequenceGeneratorusingi64