Expand description
§cuid2-timeless
An untested, somewhat stable CUID2 generator library for rust. Built for learning more rust and I don’t know how to test it.
§Usage
Either use the cuid2_timeless::cuid_wrapper()
and call it again to get ID or get some customization with cuid2_timeless::Cuid
use cuid2_timeless;
let mut cuid = cuid2_timeless::cuid_wrapper();
println!("{}", cuid().unwrap());
or some customization
use cuid2_timeless;
use rand::{self, Rng};
let mut cuid = cuid2_timeless::Cuid::new(
Box::new( // A randomizer function
|| {
rand::thread_rng().gen()
}
),
Box::new( // Your very own counter function
|mut i| {
Box::new(move || {
i += 1;
i
})
}
),
24, // Length
Box::new(cuid2_timeless::utils::create_fingerprint) // And a fingerprint creator function (im too lazy to implement)
);
cuid.generate(None).unwrap();
or verify if it actually is CUID
use cuid2_timeless;
println!("{}", cuid2_timeless::is_cuid("f9ovgvsnly7h6khwt4nx08kom".to_string(), None, None));
§Features
regex
is a feature for either remove or addregex
crate to the module. Turning this off will remove theis_cuid
function (enabled by default)random
is a feature for either remove or addrand
crate to the module. Turning this off will removeDefault
trait fromCuid
(enabled by default)sha2
is a feature for either remove or addsha2
crate to the module. Turning this off will remove SHA2 hashing algorithm, but turning this feature on will usessha2
for hashing (cannot enabled withsha3
present, compiling will error ifsha2
andsha3
is enabled, not enabled by default)sha3
is a feature for either remove or addsha3
crate to the module. Turning this off will remove SHA3 hashing algorithm, but turning this feature on will usessha3
for hashing (cannot enabled withsha2
present, compiling will error ifsha2
andsha3
is enabled, enabled by default)
Re-exports§
pub use generator::Cuid;
pub use generator::cuid_wrapper;
pub use utils::is_cuid;
Modules§
- errors
- Errors module that holds a bunch of
crate::errors::Errors
values and implementations - generator
- Generator module that holds
crate::Cuid
- utils
- Utilities