pub struct Alphabet { /* private fields */ }Expand description
The characters an ID is written with, one per digit.
The number of characters is the base: BASE62 writes IDs
in base 62. Give an ID type an alphabet with the alphabet option of
#[typedflake] to get encode and decode:
use typedflake::{Alphabet, typedflake};
// Digits and lowercase letters, without the easily confused `0`, `1`, `i`, `l`, and `o`.
pub const FRIENDLY: Alphabet = Alphabet::new("23456789abcdefghjkmnpqrstuvwxyz");
#[typedflake(epoch = "2025-01-01", alphabet = FRIENDLY)]
pub struct InviteId(i64);
let id = InviteId::try_from(232_900_560_974_681_078_i64)?;
let text = id.encode();
assert_eq!(text.as_str(), "2b76swcw35egs");
assert_eq!(InviteId::decode(&text)?, id);Every ID of a type encodes to the same number of characters. When the alphabet lists its characters in ascending ASCII order, as the presets do, encoded IDs sort the same way the IDs do.
Implementations§
Source§impl Alphabet
impl Alphabet
Sourcepub const BASE64_URL: Self
pub const BASE64_URL: Self
The 64 URL-safe characters of base64url, in ascending ASCII order so that encoded IDs stay sortable.
This is not the base64 encoding of the ID’s bytes, and a base64 decoder
will not read it. Its zero digit is -, so encoded IDs can start with
a hyphen.
Trait Implementations§
impl Copy for Alphabet
impl Eq for Alphabet
impl StructuralPartialEq for Alphabet
Auto Trait Implementations§
impl Freeze for Alphabet
impl RefUnwindSafe for Alphabet
impl Send for Alphabet
impl Sync for Alphabet
impl Unpin for Alphabet
impl UnsafeUnpin for Alphabet
impl UnwindSafe for Alphabet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more