Struct GeneralPurposeConfig
struct GeneralPurposeConfig { ... }
Contains configuration parameters for base64 encoding and decoding.
# use GeneralPurposeConfig;
let config = new
.with_encode_padding;
// further customize using `.with_*` methods as needed
The constants [PAD] and [NO_PAD] cover most use cases.
To specify the characters used, see [Alphabet].
Implementations
impl GeneralPurposeConfig
const fn new() -> SelfCreate a new config with
padding=true,decode_allow_trailing_bits=false, anddecode_padding_mode = DecodePaddingMode::RequireCanonicalPadding.This probably matches most people's expectations, but consider disabling padding to save a few bytes unless you specifically need it for compatibility with some legacy system.
const fn with_encode_padding(self: Self, padding: bool) -> SelfCreate a new config based on
selfwith an updatedpaddingsetting.If
paddingistrue, encoding will append either 1 or 2=padding characters as needed to produce an output whose length is a multiple of 4.Padding is not needed for correct decoding and only serves to waste bytes, but it's in the spec.
For new applications, consider not using padding if the decoders you're using don't require padding to be present.
const fn with_decode_allow_trailing_bits(self: Self, allow: bool) -> SelfCreate a new config based on
selfwith an updateddecode_allow_trailing_bitssetting.Most users will not need to configure this. It's useful if you need to decode base64 produced by a buggy encoder that has bits set in the unused space on the last base64 character as per forgiving-base64 decode. If invalid trailing bits are present and this is
true, those bits will be silently ignored, elseDecodeError::InvalidLastSymbolwill be emitted.const fn with_decode_padding_mode(self: Self, mode: DecodePaddingMode) -> SelfCreate a new config based on
selfwith an updateddecode_padding_modesetting.Padding is not useful in terms of representing encoded data -- it makes no difference to the decoder if padding is present or not, so if you have some un-padded input to decode, it is perfectly fine to use
DecodePaddingMode::Indifferentto prevent errors from being emitted.However, since in practice people who learned nothing from BER vs DER seem to expect base64 to have one canonical encoding, the default setting is the stricter
DecodePaddingMode::RequireCanonicalPadding.Or, if "canonical" in your circumstance means no padding rather than padding to the next multiple of four, there's
DecodePaddingMode::RequireNoPadding.
impl Clone for GeneralPurposeConfig
fn clone(self: &Self) -> GeneralPurposeConfig
impl Config for GeneralPurposeConfig
fn encode_padding(self: &Self) -> bool
impl Copy for GeneralPurposeConfig
impl Debug for GeneralPurposeConfig
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for GeneralPurposeConfig
fn default() -> SelfDelegates to [GeneralPurposeConfig::new].
impl Freeze for GeneralPurposeConfig
impl RefUnwindSafe for GeneralPurposeConfig
impl Send for GeneralPurposeConfig
impl Sync for GeneralPurposeConfig
impl Unpin for GeneralPurposeConfig
impl UnwindSafe for GeneralPurposeConfig
impl<T> Any for GeneralPurposeConfig
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for GeneralPurposeConfig
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for GeneralPurposeConfig
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for GeneralPurposeConfig
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for GeneralPurposeConfig
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for GeneralPurposeConfig
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for GeneralPurposeConfig
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for GeneralPurposeConfig
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for GeneralPurposeConfig
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>