pub trait Alphabet {
const SYMBOL_LIST: &'static [u8];
}
Expand description
A set of symbols that can be used in Nano ID. In this crate, only ASCII characters can be used as symbols.
For the list of available alphabets, see the alphabet
module.
§Implementing a custom alphabet
To implement a custom alphabet, you need to create a new type that implements the Alphabet
trait.
use nid::{alphabet::Alphabet, Nanoid};
struct CustomAlphabet;
impl Alphabet for CustomAlphabet {
const SYMBOL_LIST: &'static [u8] = b"(){}[]<>";
}
let id: Nanoid<21, CustomAlphabet> = Nanoid::new();
let id: Nanoid<21, CustomAlphabet> = "{{)((})>]<)}(>)(<)<){".parse()?;
Note that the alphabet must contain only ASCII characters. If you use an alphabet with non-ASCII characters, the compilation error will occur.
ⓘ
use nid::{alphabet::Alphabet, Nanoid};
struct CustomAlphabet;
impl Alphabet for CustomAlphabet {
const SYMBOL_LIST: &'static [u8] = b"abc012\xa0\xa1";
}
let id: Nanoid<21, CustomAlphabet> = Nanoid::new(); // Compilation error: found non-ascii symbol in alphabet
Required Associated Constants§
sourceconst SYMBOL_LIST: &'static [u8]
const SYMBOL_LIST: &'static [u8]
The symbols that can be used in Nano ID. Symbols are represented as u8
values.
Object Safety§
This trait is not object safe.