Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

For configuring how a string is encoded/decoded.

Config has these values by default:

  • end_padding = true

Implementations§

Source§

impl Config

Source

pub const fn new(encoding: Encoding) -> Self

Constructs a Config from an Encoding

You can use the associated constants for a more concise way to get a Config

§Example
use const_base::{B64CharSet, Config, Encoding, encode};

// The same as `Config::B64`
const CFG: Config = Config::new(Encoding::Base64(B64CharSet::Standard));

assert_eq!(encode!("Rust", CFG), "UnVzdA==")
Source

pub const fn end_padding(self, have: bool) -> Self

Determines whether the string has padding at the end. This is true by default.

For each encoding, the strings are padded to a multiple:

  • Base64: pads to be a multiple of 4 long, with =.
  • Base32: pads to be a multiple of 8 long, with =.
  • Hexadecimal: requires no padding
§Examples
§Base 64
use const_base::{Config, encode};

assert_eq!(encode!("Rust", Config::B64), "UnVzdA==");

assert_eq!(encode!("Rust", Config::B64.end_padding(true)), "UnVzdA==");

assert_eq!(encode!("Rust", Config::B64.end_padding(false)), "UnVzdA");
§Base 32
use const_base::{Config, encode};

assert_eq!(encode!("Rustic", Config::B32), "KJ2XG5DJMM======");

assert_eq!(encode!("Rustic", Config::B32.end_padding(true)), "KJ2XG5DJMM======");

assert_eq!(encode!("Rustic", Config::B32.end_padding(false)), "KJ2XG5DJMM");
Source

pub const fn encode<const OUT: usize>( self, input: &[u8], ) -> Result<ArrayStr<OUT>, WrongOutputLength>

A different way to call encode.

§Example
use const_base::{Config, encode};

assert_eq!(Config::B64.encode::<8>(b"Rust").unwrap(), "UnVzdA==");
Source

pub const fn decode<const OUT: usize>( self, input: &[u8], ) -> Result<[u8; OUT], DecodeError>

A different way to call decode.

§Example
use const_base::{Config, decode};

assert_eq!(Config::B64.decode::<4>(b"UnVzdA=="), Ok(*b"Rust"));
Source§

impl Config

Source

pub const B64: Self

Configuration with the Base64 encoding, using the Standard character set.

§Example
use const_base::{Config, encode};

assert_eq!(encode!(&[23, 239, 192], Config::B64), "F+/A");
Source

pub const B64_URL_SAFE: Self

Configuration with the Base64 encoding, using the UrlSafe character set.

§Example
use const_base::{Config, encode};

assert_eq!(encode!(&[23, 239, 192], Config::B64_URL_SAFE), "F-_A");
Source

pub const B32: Self

Configuration with the Base32 encoding, using the Standard character set.

§Example
use const_base::{Config, encode};

assert_eq!(encode!(b"neat", Config::B32), "NZSWC5A=");
Source

pub const HEX: Self

Configuration with the Hex (hexadecimal) encoding, using the Uppercase character set.

§Example
use const_base::{Config, decode, encode};

assert_eq!(encode!(&[0xF1, 0x00, 0x0f], Config::HEX), "F1000F");

// Hexademical decoding allows mixing uppercase and lowercase
assert_eq!(decode!(b"beefBEEF", Config::HEX), &[0xBE, 0xEF, 0xBE, 0xEF]);
Source

pub const HEX_LOWER: Self

Configuration with the Hex (hexadecimal) encoding, using the Lowercase character set.

§Example
use const_base::{Config, decode, encode};

assert_eq!(encode!(&[0xf1, 0x00, 0x0f], Config::HEX_LOWER), "f1000f");

// Hexademical decoding allows mixing uppercase and lowercase
assert_eq!(decode!(b"beefBEEF", Config::HEX_LOWER), &[0xBE, 0xEF, 0xBE, 0xEF]);

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.