macro_rules! encode_as_str {
($slice:expr, $config:expr $(,)*) => { ... };
}Expand description
Encodes the $slice constant into a &'static str,
with the encoding determined by $config.
$slice can be a &'static str, &'static [u8; N], or &'static [u8].
§Examples
§Base 64
use const_base::{encode_as_str, Config};
{
const OUT: &str = encode_as_str!("qux", Config::B64);
assert_eq!(OUT, "cXV4");
}
{
const BYTES: &[u8] = b"goodbye";
const OUT: &str = encode_as_str!(BYTES, Config::B64_URL_SAFE);
assert_eq!(OUT, "Z29vZGJ5ZQ==");
}§Base 32
use const_base::{encode_as_str, Config};
const OUT: &str = encode_as_str!(&[13, 21, 34], Config::B32);
assert_eq!(OUT, "BUKSE===");§Hexadecimal
use const_base::{encode_as_str, Config};
const UPPER: &str = encode_as_str!(&[0xB1, 0x00, 0x0d], Config::HEX);
const LOWER: &str = encode_as_str!(&[0xB1, 0x00, 0x0d], Config::HEX_LOWER);
assert_eq!(UPPER, "B1000D");
assert_eq!(LOWER, "b1000d");