6 releases

0.1.5 Jul 25, 2022
0.1.4 May 31, 2022
0.1.3 May 18, 2020

#57 in Value formatting

Download history 174/week @ 2023-12-13 114/week @ 2023-12-20 49/week @ 2023-12-27 69/week @ 2024-01-03 126/week @ 2024-01-10 232/week @ 2024-01-17 137/week @ 2024-01-24 125/week @ 2024-01-31 122/week @ 2024-02-07 171/week @ 2024-02-14 168/week @ 2024-02-21 216/week @ 2024-02-28 248/week @ 2024-03-06 326/week @ 2024-03-13 676/week @ 2024-03-20 484/week @ 2024-03-27

1,754 downloads per month
Used in 29 crates (8 directly)

Custom license

17KB
138 lines

Crate unique_id

A trait and implementations for unique ID generators.

MIT License Minimum Rust Version crates.io docs.rs Build Audit GitHub stars

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.

Example

The following shows an example of the StringGenerator implementation.

use unique_id::Generator;
use unique_id::string::StringGenerator;

let gen = StringGenerator::default();
let mut last = gen.next_id();
for _ in 1..100_000 {
    let next = gen.next_id();
    assert_ne!(last, next);
    last = next;
}

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.

$ cargo bench

    Finished bench [optimized] target(s) in 17.16s
     Running target/release/deps/unique_id-4944964a39587480

running 3 tests
test random::tests::test_something ... ignored
test sequence::tests::test_something ... ignored
test string::tests::test_something ... ignored

test result: ok. 0 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out

     Running target/release/deps/compare-cfeb3571caa9de30
Compare Implementations/string
                        time:   [928.16 ns 1.0963 us 1.2829 us]
                        change: [+108.47% +224.51% +419.70%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe
Compare Implementations/integer
                        time:   [21.033 ns 21.434 ns 21.885 ns]
                        change: [-4.1097% +0.4756% +5.4467%] (p = 0.84 > 0.05)
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe
Compare Implementations/random
                        time:   [36.741 ns 38.285 ns 40.487 ns]
                        change: [-33.414% -24.047% -13.624%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  2 (2.00%) high mild
  5 (5.00%) high severe

The output can be found in target/criterion/report/index.html.

Changes

Version 0.1.5

  • Simplified implementation of SequenceGenerator.
  • Removed atomic_refcell dependency.

Version 0.1.4

  • Updated dependencies for uuid and blob-uuid via dependabot.
  • Removed PhantomData in generator structures.

Version 0.1.3

  • Moved module-specific unit tests into a combined tests/unique.rs.
  • Renamed integer to sequence in benchmarks.
  • Added more to the documentation.

Version 0.1.2

  • Added new RandomGenerator implementation.
  • Put each implementation into its own feature.
  • Added #[inline] to some functions.

Version 0.1.1

  • Added trait GeneratorFromSeed and implementation for SequenceGenerator.
  • Added a benchmark to compare the two current implementations.

Version 0.1.0

  • Simple traits Generator, GeneratorWithInvalid, and GeneratorFromStr.
  • StringGenerator using UUIDs
  • SequenceGenerator using i64

Dependencies

~92KB