Macro const_base::encode [−][src]
macro_rules! encode { ($slice : expr, $config : expr $(,) *) => { ... }; }
Expand description
Encodes the $slice
constant into a &[u8; N]
with the encoding determined by $config
.
$slice
slice can be a &'static str
, &'static [u8; N]
, or &'static [u8]
.
Examples
Base 64
use const_base::{encode, Config}; { const OUT: &[u8; 4] = encode!("bar", Config::B64); assert_eq!(OUT, b"YmFy"); } { const BYTES: &[u8] = b"world"; // this macro can encode non-literal constants const OUT: &[u8] = encode!(BYTES, Config::B64_URL_SAFE); assert_eq!(OUT, b"d29ybGQ="); }
Base 32
use const_base::{encode, Config}; const OUT: &[u8] = encode!(&[3, 5, 8], Config::B32); assert_eq!(OUT, b"AMCQQ===");
Base 32
use const_base::{encode, Config}; const OUT: &[u8] = encode!(&[3, 5, 8], Config::B32); assert_eq!(OUT, b"AMCQQ===");
Hexadecimal
use const_base::{encode, Config}; const LOWER: &[u8] = encode!(&[0xB0, 0x01], Config::HEX_LOWER); const UPPER: &[u8] = encode!(&[0xB0, 0x01], Config::HEX); assert_eq!(LOWER, b"b001"); assert_eq!(UPPER, b"B001");