Expand description
This module defines the Alphabet
trait and provides implementations for the most common alphabets used in Nano ID.
An alphabet is a set of symbols that can be used in Nano ID. In this crate, only ASCII characters can be used as symbols.
The default alphabet used in Nano ID is Base64UrlAlphabet
, which contains A-Za-z0-9_-
symbols.
§Implementing a custom alphabet
To implement a custom alphabet, you need to create a new type that implements the Alphabet
trait.
§Examples
use nid::{alphabet::{Base36Alphabet, Base58Alphabet}, Nanoid};
// Use the default Base64URL alphabet, which contains `A-Za-z0-9_-` symbols.
type ShopId = Nanoid<9>;
let id: ShopId = Nanoid::new();
let id: ShopId = "kP_IH1DPM".parse()?;
// Use Base36 alphabet, which contains `A-Z0-9` symbols.
type UserId = Nanoid<21, Base36Alphabet>;
let id: UserId = Nanoid::new();
let id: UserId = "NDBIZRQSB6OGXJS06AN5L".parse()?;
// Use Base58 alphabet, which contains `A-Za-z0-9` symbols excluding `0OlI`.
type ItemId = Nanoid<16, Base58Alphabet>;
let id: ItemId = Nanoid::new();
let id: ItemId = "96MrjhHuWXJMLCKh".parse()?;
Structs§
- Alphabet with
A-F0-9
symbols. - Alphabet with
a-f0-9
symbols. - Alphabet with
A-Z2-7
symbols. - Alphabet with
a-z2-7
symbols. - Alphabet with
A-Z0-9
symbols. - Alphabet with
a-z0-9
symbols. - Alphabet with
A-Za-z0-9
symbols excluding0OlI
. - Alphabet with
A-Za-z0-9
symbols. - Alphabet with
A-Za-z0-9_-
symbols. This is the default alphabet used in Nano ID.
Traits§
- A set of symbols that can be used in Nano ID. In this crate, only ASCII characters can be used as symbols.