Macro const_base::encode_as_str [−][src]
macro_rules! encode_as_str { ($slice : expr, $config : expr $(,) *) => { ... }; }
Expand description
Encodes the $slice
constant into a &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"; // this macro can encode non-literal constants 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 LOWER: &str = encode_as_str!(&[0xB1, 0x00, 0x0d], Config::HEX_LOWER); const UPPER: &str = encode_as_str!(&[0xB1, 0x00, 0x0d], Config::HEX); assert_eq!(LOWER, "b1000d"); assert_eq!(UPPER, "B1000D");