Struct const_base::Config[][src]

pub struct Config { /* fields omitted */ }
Expand description

For configuring how a string is encoded/decoded.

Config has these values by default:

  • end_padding = false

Implementations

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), b"UnVzdA==")

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

For base64 strings, the string is padded to be a multiple of 4 long, with =.

Example

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

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

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

assert_eq!(encode!("Rust", Config::B64.end_padding(false)), b"UnVzdA");

A different way to call encode.

Example

use const_base::{Config, encode};

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

A different way to call decode.

Example

use const_base::{Config, decode};

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

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

Example

use const_base::{Config, encode};

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

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), b"F-_A");

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

Example

use const_base::{Config, encode};

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

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), b"F1000F");

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

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), b"f1000f");

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.