#[derive(Debug)]
pub struct Alphabet<const N: usize = 64>(pub(crate) [char; N]);
pub type HexAlphabet = Alphabet<16>;
impl Default for &'static Alphabet {
fn default() -> Self {
&DEFAULT
}
}
impl Default for &'static HexAlphabet {
fn default() -> Self {
&HEX
}
}
impl<const N: usize> Alphabet<N> {
#[track_caller]
pub const fn new(chars: [char; N]) -> Self {
assert!(
N.is_power_of_two(),
"Alphabet must have a length that is a power of two"
);
assert!(N != 0, "Alphabet cannot be empty");
assert!(
N <= u8::max_value() as usize,
"The alphabet cannot be longer than a `u8`"
);
Alphabet(chars)
}
}
pub const DEFAULT: Alphabet = Alphabet([
'_', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
]);
pub const HEX: Alphabet<16> = Alphabet([
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
]);
pub const HEX_UPPER: Alphabet<16> = Alphabet([
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
]);