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
impl Config
Sourcepub const fn new(encoding: Encoding) -> Self
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==")
Sourcepub const fn end_padding(self, have: bool) -> Self
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§impl Config
impl Config
Sourcepub const B64_URL_SAFE: Self
pub const B64_URL_SAFE: Self
Sourcepub const HEX: Self
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]);Sourcepub const HEX_LOWER: Self
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more