12 releases
Uses new Rust 2024
| new 0.2.0 | Feb 6, 2026 |
|---|---|
| 0.1.2 | Feb 6, 2026 |
| 0.0.8 | Jan 26, 2026 |
#477 in Cryptography
Used in tnid-cli
215KB
3K
SLoC
TNID
UUID-compatible IDs with names and compile-time type safety.
TNIDs are UUIDv8-compatible identifiers that include a human-readable name and can be strictly typed at compile time.
use tnid::{Case, NameStr, Tnid, TnidName};
struct User;
impl TnidName for User {
const ID_NAME: NameStr<'static> = NameStr::new_const("user");
}
// Create a time-ordered ID (like UUIDv7)
let user_id = Tnid::<User>::new_time_ordered();
println!("{}", user_id); // user.Br2flcNDfF6LYICnT
// Or a high-entropy ID (like UUIDv4)
let session_id = Tnid::<User>::new_high_entropy();
Why TNIDs?
- Type-safe:
Tnid<User>andTnid<Post>are different types. Accidentally passing a post ID to auserfunction? Compile error. - Named: IDs include a human-readable name prefix. See
user.Br2flcNDfF6LYICnTin your logs and instantly know what it is. - UUID-compatible: TNIDs are valid UUIDv8s that work directly with Postgres UUID columns and UUID-expecting APIs.
- Compile-time validated: Try to create a TNID with name "INVALID"? Your code won't even compile.
- Sortable strings: Unlike UUID hex (case-insensitive mess), TNID strings sort correctly and have exactly one representation.
Status
Beta: The TNID spec is still being finalized and shouldn't be relied on for production use yet. This implementation tracks the evolving spec.
A full specification site will be available at tnid.info.
Installation
cargo add tnid
Documentation
See the API documentation for complete details, examples, and feature flags.
License
MIT
Dependencies
~1–18MB
~190K SLoC