A small, 8-byte, ID type for use in rust applications that need a pretty unique identifier that is not required to be cryptographically secure / correct. They can be randomly generated but no work has been done to make sure that these random generations are secure (all RNG is done through the excellent fastrand
crate).
I made this type because I needed mostly / somewhat random identifiers that could be easily read and retyped by a user, but would also prevent collisions in somewhat small (less than a million or so) applications.
The crate has either one or two dependencies, depending on whether serialization is needed. fastrand
is used for RNG, serde
is used for de/serialization only if the serde
feature flag is enabled.
Further examples can be found in ./examples/basic.rs.
```rust use tinyid::TinyId;
// Generate a random ID. let mut id = TinyId::random(); // Ensure that the ID is valid. assert!(id.isvalid()); assert!(!id.isnull());
id.makenull(); assert!(!id.isvalid()); assert!(id.isnull()); asserteq!(id, TinyId::null()); ```
The crate only has one feature, serde
, which will enable serde serialization and deserialization of the TinyId
type. It will also bring in the serde
dependency.