| Crates.io | mtid |
| lib.rs | mtid |
| version | 0.6.1 |
| created_at | 2025-10-13 05:57:56.32439+00 |
| updated_at | 2025-11-13 20:56:31.299633+00 |
| description | Human-friendly id for personal distributed system (deprecated, use the caretta-id crate) |
| homepage | https://github.com/fluo10/mtid |
| repository | https://github.com/fluo10/mtid |
| max_upload_size | |
| id | 1880068 |
| size | 138,160 |
The mtid crate has been renamed to caretta-id. Please use the caretta-id crate instead.
A human-friendly identifier format based on 3-character blocks ("triplet"). This crate provides multiple fixed-length variants:
Stid: Single triplet ID (e.g. 123)Dtid: Double Triplet ID (e.g. 456-789)Ttid: Triple Triplet ID (e.g. abc-def-ghj)Qtid: Quadruple triplet ID (e.g. kmn-pqr-stv-wxy)For a language agnostic specification of the MTID format, see SPECS.md
use mtid::Dtid;
let id = Dtid::random();
println!("{}", id); // e.g. "1a2-b3c"
Traditional identifier systems face challenges in distributed environments:
MTID bridges the gap between human readability and technical requirements.
Add this to your Cargo.toml:
[dependencies]
mtid = "0.6"
# With optional features
mtid = { version = "0.6", features = ["arbitrary", "serde", "rusqlite", "sea-orm", "prost"] }
This crate support no_std.
For no_std environment, you'll need to disable default features.
[dependencies]
mtid = { version = "0.6", default-features = false }
arbitrary: arbitrary::Arbitrary support for fuzzing tests.serde: Serialization/deserialization supportrusqlite: SQLite database integrationsea-orm: SeaORM ORM integrationprost: Protocol Buffers supportuse mtid::{Stid, Dtid, Ttid, Qtid};
// Generate random MTID
let stid = Stid::random();
let dtid = Dtid::random();
let ttid = Ttid::random();
let qtid = Qtid::random();
// '123', '456-789', 'abc-def-ghj', 'kmn-pqr-stv-wxy'
println!("'{}', '{}', '{}'. '{}'", stid, dtid, ttid, qtid);
// Parse from string
let valid_id: Dtid = "012-tvw".parse()?;
// The code without delimiter is valid.
let valid_id_without_delimiter: Dtid = "012tvw".parse()?;
assert_eq!(valid_id, valid_id_without_delimiter);
// When decoding from BASE32, ambiguous characters (1/l/I, 0/o, v/u, -/_) are treated as 1, 0, v, and - respectively, so they do not cause errors.
let also_valid_id: Dtid = "ol2_tuw".parse()?;
assert_eq!(valid_id, also_valid_id);
// Convert to/from integer
let num: u32 = valid_id.into();
let id_from_int: Dtid = num.try_into()?;
assert_eq!(valid_id, id_from_int);
// Lossy conversion from oversized int is allowed.
let id_from_overflowed_int = Dtid::from_uint_lossy(Dtid::CAPACITY + num);
assert_eq!(valid_id, id_from_overflowed_int);
Licensed under either of:
at your option.