Expand description
§moid — minimal opaque ID
Mint short, opaque identifiers over a configurable alphabet, with an optional NOID-style check character for typo detection. That is the whole crate.
use moid::{Alphabet, Minter, SeededRng};
// 6 random betanumeric symbols + 1 check character = a 7-char id.
let minter = Minter::new(Alphabet::betanumeric(), 6);
let id = minter.mint_seeded(&mut SeededRng::new(42));
assert!(minter.validate(&id).is_ok());§Scope: mint only
moid mints and validates. It deliberately does not do the other two things the NOID tool bundles:
- Binding (id → value/metadata) — that is a stateful store; keep it in your own registry/index.
- Resolution (id → target, over HTTP) — that is a resolver/proxy.
Folding either into the minter would require persistent state and pull in platform-specific storage, forfeiting the dependency-free core that lets moid link into WASM and Extism guests. So they are out of scope by design, not by omission.
§Non-goals
These are declined on purpose, so that “minimal” is a promise rather than an omission:
- Binding and resolution — see Scope above; both need persistent state and belong in your own registry or resolver.
- Serialization /
serde— anAlphabetis a handful of ASCII bytes (Alphabet::as_str) and aMinteris a few plain fields; reconstruct them from your own config rather than pulling in a derive. - Sortable or time-encoded ids (ULID-, KSUID-, Snowflake-style) — moid mints opaque handles that carry no embedded timestamp or ordering; reach for a dedicated crate when you need lexicographic sort keys.
- Cryptographic randomness guarantees — the built-in
SeededRngis a deterministic, non-cryptographic PRNG; uniqueness comes from rejection against a taken-set, not from entropy strength. Supply your own CSPRNG bytes (or useMinter::mint_os) when unpredictability matters.
§no_std
The core is #![no_std],
depending only on alloc for the String it mints.
The default std feature adds nothing but
impl std::error::Error for MoidError;
disable it (default-features = false) to link into a no_std target.
§Entropy
Every mint takes caller-supplied bytes, so the core has no dependencies and runs anywhere. Two conveniences layer on top:
SeededRng— a deterministicxorshift64(dependency-free; for tests and reproducibility).Minter::mint_os— ambient OS/browser entropy viagetrandom, behind theos(native/WASI) andjs(browser wasm) features.
The check-character algorithm is NOID’s; the result matches a standard
NOID minter only when you mint over Alphabet::noid_xdigit. The
betanumeric set (Alphabet::betanumeric) is one preset among
several.
Modules§
- presets
- Ready-made alphabets. Pass one to
Alphabet::new, or use the matching constructor (e.g.Alphabet::betanumeric).
Structs§
- Alphabet
- A validated set of ASCII symbols an id is minted from.
- Minter
- A configured minter. Cheap to clone; holds no entropy of its own (you supply
that per call), so it stays
Clone/Debugand reusable. - Seeded
Rng - A small, dependency-free, deterministic
xorshift64byte source.
Enums§
- Moid
Error - Errors produced while constructing an
crate::Alphabetor validating a minted id.