Trait nid::alphabet::Alphabet

source ·
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§

source

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.

Implementors§

source§

impl Alphabet for Base16Alphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEF0123456789"

source§

impl Alphabet for Base16LowercaseAlphabet

source§

const SYMBOL_LIST: &'static [u8] = b"abcdef0123456789"

source§

impl Alphabet for Base32Alphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"

source§

impl Alphabet for Base32LowercaseAlphabet

source§

const SYMBOL_LIST: &'static [u8] = b"abcdefghijklmnopqrstuvwxyz234567"

source§

impl Alphabet for Base36Alphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

source§

impl Alphabet for Base36LowercaseAlphabet

source§

const SYMBOL_LIST: &'static [u8] = b"abcdefghijklmnopqrstuvwxyz0123456789"

source§

impl Alphabet for Base58Alphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz123456789"

source§

impl Alphabet for Base62Alphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

source§

impl Alphabet for Base64UrlAlphabet

source§

const SYMBOL_LIST: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"