Expand description
A trait and implementations for unique ID generators.
This crate provides a very simple trait, Generator
, that will return successive unique identifiers. Two
implementations of this trait are provided which provide unique string and integer values respectively.
§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;
}
Modules§
- random
- An implementation that provides random 128-bit unsigned integer values.
- sequence
- An implementation that provides monotonically increasing integer values.
- string
- An implementation that provides unique string values.
Traits§
- Generator
- The primary ID generator trait, it provides for generating a new ID with
next_id()
. There is no implication that this returns any overall sequence of values, only that it returns a unique value for each call. - Generator
From Seed - While it is required for a generator to support the
Default
trait, in some cases it is useful to create a new generator some some known initial value, the seed. - Generator
From Str - If the type
T
implementsFromStr
then the associated functionis_valid_value
determines whether the values
is valid as an ID value. - Generator
With Invalid - For generators that are able to reserve a unique value that is not valid as an ID.