Alphabet
The characters a short id is made of: between 2 and 256 distinct characters.
Presets cover the common cases; new checks a custom set. Every character has
the same probability in an id, which needs them distinct (a repeated character would be more
likely) and no more than a byte of randomness can index (256).
Import
Section titled “Import”Cargo feature id (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”A custom alphabet.
Parameters
| Parameter | Type | Description |
|---|---|---|
characters | &str | The characters, each once, in any order. |
Returns
Result<Self, AlphabetError> — The alphabet.
Errors
Returns an AlphabetError for fewer than 2 characters, more than 256, or a repeated
character.
Examples
numbers
Section titled “numbers”The digits 0-9.
Returns
Self — The alphabet.
Examples
lowercase
Section titled “lowercase”The lowercase letters a-z.
Returns
Self — The alphabet.
Examples
uppercase
Section titled “uppercase”The uppercase letters A-Z.
Returns
Self — The alphabet.
Examples
alphanumeric
Section titled “alphanumeric”Letters and digits, A-Za-z0-9.
Returns
Self — The alphabet.
Examples
url_safe
Section titled “url_safe”The 64 characters that are safe in a URL path and a file name without escaping:
A-Za-z0-9_-.
Returns
Self — The alphabet.
Examples
Letters and digits without the characters that look alike, for ids a person reads or
types: no 0, 1, O, o, I or l.
Returns
Self — The alphabet, 56 characters.
Examples
The number of characters.
Returns
usize — A number from 2 to 256.
Examples
Error type: AlphabetError
Section titled “Error type: AlphabetError”Why a string cannot be an Alphabet.
