Struct Alphabet

struct Alphabet { ... }

An alphabet defines the 64 ASCII characters (symbols) used for base64.

Common alphabets are provided as constants, and custom alphabets can be made via from_str or the TryFrom<str> implementation.

Examples

Building and using a custom Alphabet:

let custom = base64::alphabet::Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap();

let engine = base64::engine::GeneralPurpose::new(
    &custom,
    base64::engine::general_purpose::PAD);

Building a const:

use base64::alphabet::Alphabet;

static CUSTOM: Alphabet = {
    // Result::unwrap() isn't const yet, but panic!() is OK
    match Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") {
        Ok(x) => x,
        Err(_) => panic!("creation of alphabet failed"),
    }
};

Building lazily:

use base64::{
    alphabet::Alphabet,
    engine::{general_purpose::GeneralPurpose, GeneralPurposeConfig},
};
use once_cell::sync::Lazy;

static CUSTOM: Lazy<Alphabet> = Lazy::new(||
    Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap()
);

Implementations

impl Alphabet

const fn new(alphabet: &str) -> Result<Self, ParseAlphabetError>

Create an Alphabet from a string of 64 unique printable ASCII bytes.

The = byte is not allowed as it is used for padding.

fn as_str(self: &Self) -> &str

Create a &str from the symbols in the Alphabet

impl Clone for Alphabet

fn clone(self: &Self) -> Alphabet

impl Debug for Alphabet

fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result

impl Eq for Alphabet

impl Freeze for Alphabet

impl PartialEq for Alphabet

fn eq(self: &Self, other: &Alphabet) -> bool

impl RefUnwindSafe for Alphabet

impl Send for Alphabet

impl StructuralPartialEq for Alphabet

impl Sync for Alphabet

impl TryFrom for Alphabet

fn try_from(value: &str) -> Result<Self, <Self as >::Error>

impl Unpin for Alphabet

impl UnwindSafe for Alphabet

impl<T> Any for Alphabet

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Alphabet

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Alphabet

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Alphabet

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Alphabet

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Alphabet

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Alphabet

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Alphabet

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Alphabet

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>