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
regexis a feature for either remove or addregexcrate to the module. Turning this off will remove theis_cuidfunction (enabled by default)randomis a feature for either remove or addrandcrate to the module. Turning this off will removeDefaulttrait fromCuid(enabled by default)sha2is a feature for either remove or addsha2crate to the module. Turning this off will remove SHA2 hashing algorithm, but turning this feature on will usessha2for hashing (cannot enabled withsha3present, compiling will error ifsha2andsha3is enabled, not enabled by default)sha3is a feature for either remove or addsha3crate to the module. Turning this off will remove SHA3 hashing algorithm, but turning this feature on will usessha3for hashing (cannot enabled withsha2present, compiling will error ifsha2andsha3is 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::Errorsvalues and implementations - generator
- Generator module that holds
crate::Cuid - utils
- Utilities