glecuid/cuid2
Types
Values
pub fn create_id() -> String
Generates a CUIDv2 using the default generator.
Examples
cuid2.create_id()
// -> "avu4793cnw6ljhov1s7Oxidg"
pub fn generate(g: Generator) -> String
Generates a CUIDv2 using custom generator.
Examples
cuid2.new()
|> cuid2.with_length(10)
|> cuid2.with_fingerprint("my_machine")
|> cuid2.with_counter(fn() { int.random(100) })
|> cuid2.with_randomizer(fn() { 0.5 })
|> cuid2.generate()
// -> "av77nekw5e"
pub fn is_cuid(input: String) -> Bool
Determines whether or not the string is a valid CUIDv2.
pub fn with_counter(
g: Generator,
counter: fn() -> Int,
) -> Generator
Sets a custom counter to be used by the Generator.
Counter is a function that returns an incrementing Int
every time it is called.
pub fn with_fingerprint(
g: Generator,
fingerprint: String,
) -> Generator
Sets a custom fingerprint to be used by the Generator.
Fingerprint is a unique String to help prevent collision
when generating ids in a distributed system.
pub fn with_length(g: Generator, length: Int) -> Generator
Sets the length of the ids generated by the Generator.
pub fn with_random_counter(g: Generator) -> Generator
Sets a random counter to be used by the Generator.
This counter returns a random Int instead of an incrementing value.