cuid2_timeless/lib.rs
1//! # cuid2-timeless
2//!
3//! An untested, somewhat stable CUID2 generator library for rust. Built for learning more rust and I don't know how to test it.
4//!
5//! ## Usage
6//!
7//! Either use the `cuid2_timeless::cuid_wrapper()` and call it again to get ID or get some customization with `cuid2_timeless::Cuid`
8//!
9//! ``` rust
10//! use cuid2_timeless;
11//!
12//! let mut cuid = cuid2_timeless::cuid_wrapper();
13//! println!("{}", cuid().unwrap());
14//! ```
15//!
16//! or some customization
17//!
18//! ```rust
19//! use cuid2_timeless;
20//! use rand::{self, Rng};
21//!
22//! let mut cuid = cuid2_timeless::Cuid::new(
23//! Box::new( // A randomizer function
24//! || {
25//! rand::thread_rng().gen()
26//! }
27//! ),
28//! Box::new( // Your very own counter function
29//! |mut i| {
30//! Box::new(move || {
31//! i += 1;
32//! i
33//! })
34//! }
35//! ),
36//! 24, // Length
37//! Box::new(cuid2_timeless::utils::create_fingerprint) // And a fingerprint creator function (im too lazy to implement)
38//! );
39//! cuid.generate(None).unwrap();
40//! ```
41//!
42//! or verify if it actually is `CUID`
43//!
44//! ```rust
45//! use cuid2_timeless;
46//!
47//! println!("{}", cuid2_timeless::is_cuid("f9ovgvsnly7h6khwt4nx08kom".to_string(), None, None));
48//! ```
49//! ## Features
50//!
51//! - `regex` is a feature for either remove or add [`regex`] crate to the module. Turning this off will remove the [`is_cuid`] function (enabled by default)
52//! - `random` is a feature for either remove or add [`rand`] crate to the module. Turning this off will remove [`Default`] trait from [`Cuid`] (enabled by default)
53//! - `sha2` is a feature for either remove or add `sha2` crate to the module. Turning this off will remove SHA2 hashing algorithm, but turning this feature on will uses `sha2` for hashing (cannot enabled with `sha3` present, compiling will error if `sha2` and `sha3` is enabled, not enabled by default)
54//! - `sha3` is a feature for either remove or add `sha3` crate to the module. Turning this off will remove SHA3 hashing algorithm, but turning this feature on will uses `sha3` for hashing (cannot enabled with `sha2` present, compiling will error if `sha2` and `sha3` is enabled, enabled by default)
55
56#![warn(missing_docs)]
57
58/// Errors module that holds a bunch of [`crate::errors::Errors`] values and implementations
59pub mod errors;
60/// Generator module that holds [`crate::Cuid`]
61pub mod generator;
62
63/// Utilities
64pub mod utils;
65
66pub use generator::Cuid;
67
68#[cfg(feature = "random")]
69pub use generator::cuid_wrapper;
70
71#[cfg(feature = "regex")]
72pub use utils::is_cuid;
73#[cfg(all(test, feature="tests"))]
74/// it's tests, what do you expect
75pub mod tests;