pub struct Encoder { /* private fields */ }Expand description
BASE64 encoder struct
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new instance of the encoder using the default base64 alphabet
§Examples
use irelia_encoder::Encoder;
const ENCODER: Encoder = Encoder::new();Sourcepub const fn with_encode_table(encode_table: [u8; 64]) -> Self
pub const fn with_encode_table(encode_table: [u8; 64]) -> Self
Creates a new instance of the encoder using a specified alphabet
§Example:
use irelia_encoder::Encoder;
const ALPHABET: [u8; 64] = [
b'A', b'B', b'C', b'D', b'E', b'F', b'G', b'H', b'I', b'J', b'K', b'L', b'M', b'N',
b'O', b'P', b'Q', b'R', b'S', b'T', b'U', b'V', b'W', b'X', b'Y', b'Z', b'a', b'b',
b'c', b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm', b'n', b'o', b'p',
b'q', b'r', b's', b't', b'u', b'v', b'w', b'x', b'y', b'z', b'0', b'1', b'2', b'3',
b'4', b'5', b'6', b'7', b'8', b'9', b'+', b'/',
];
const ENCODER: Encoder = Encoder::with_encode_table(ALPHABET);Sourcepub fn encode_with_ascii_check<T>(&self, bytes: T) -> String
pub fn encode_with_ascii_check<T>(&self, bytes: T) -> String
Converts the bytes to BASE64, and validates that the BASE64 is all ASCII
§Examples
use irelia_encoder::Encoder;
const ENCODER: Encoder = Encoder::new();
let base64_encoded = ENCODER.encode_with_ascii_check("Hello, World!");§Panics
This function panics if the buffer produced is not valid ASCII This should not happen if the default alphabet is in use
Sourcepub unsafe fn encode_unchecked<T>(&self, bytes: T) -> String
pub unsafe fn encode_unchecked<T>(&self, bytes: T) -> String
Converts the bytes to BASE64, but doesn’t check if the output is valid UTF-8
§Example:
use irelia_encoder::Encoder;
const ENCODER: Encoder = Encoder::new();
let base64_encoded = unsafe { ENCODER.encode_unchecked("Hello, World!") };§Safety
The characters used for the encode table need to be valid UTF-8 This is true with the default table, but might not be for custom ones.
Sourcepub fn encode_without_padding<T>(&self, bytes: T) -> String
pub fn encode_without_padding<T>(&self, bytes: T) -> String
Sourcepub unsafe fn encode_unchecked_without_padding<T>(&self, bytes: T) -> String
pub unsafe fn encode_unchecked_without_padding<T>(&self, bytes: T) -> String
Converts the bytes to BASE64 without padding, but doesn’t check if the output is valid UTF-8
§Example:
use irelia_encoder::Encoder;
const ENCODER: Encoder = Encoder::new();
let base64_encoded = unsafe { ENCODER.encode_unchecked("Hello, World!") };§Safety
The characters used for the encode table need to be valid UTF-8 This is true with the default table, but might not be for custom ones.