Crate data_encoding_macro [−] [src]
Macros for data-encoding
This library provides macros to define compile-time byte arrays from encoded strings (using common bases like base64, base32, or hexadecimal, and also custom bases). It also provides a macro to define compile-time custom encodings to be used with the data-encoding crate at run-time.
If you were familiar with the binary_macros crate, this library is actually inspired from it.
If you use a nightly compiler, you may disable the "stable" feature:
data-encoding-macro = { version = "0.1.0", default-features = false }
Examples
You can define a compile-time byte slice from an encoded string literal:
#[macro_use] extern crate data_encoding_macro; const HELLO_SLICE: &'static [u8] = &hexlower!("68656c6c6f"); const FOOBAR_SLICE: &'static [u8] = &base64!("Zm9vYmFy");
When you disable the "stable" feature (and use a nightly compiler), you can also define a compile-time byte array from an encoded string literal:
hexlower_array!("const HELLO" = "68656c6c6f"); base64_array!("const FOOBAR" = "Zm9vYmFy");
You can define a compile-time custom encoding from its specification:
#![cfg_attr(not(feature = "stable"), feature(use_extern_macros))] extern crate data_encoding; #[macro_use] extern crate data_encoding_macro; use data_encoding::Encoding; const HEX: Encoding = new_encoding!{ symbols: "0123456789abcdef", translate_from: "ABCDEF", translate_to: "abcdef", }; const BASE64: Encoding = new_encoding!{ symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", padding: '=', };
Macros
base32 | |
base64 | |
base32_array | |
base32_dnscurve | |
base32_dnscurve_array | |
base32_dnssec | |
base32_dnssec_array | |
base32_nopad | |
base32_nopad_array | |
base32hex | |
base32hex_array | |
base32hex_nopad | |
base32hex_nopad_array | |
base64_array | |
base64_mime | |
base64_mime_array | |
base64_nopad | |
base64_nopad_array | |
base64url | |
base64url_array | |
base64url_nopad | |
base64url_nopad_array | |
decode_array |
Defines a compile-time byte array by decoding a string literal |
decode_slice |
Defines a compile-time byte slice by decoding a string literal |
hexlower | |
hexlower_array | |
hexlower_permissive | |
hexlower_permissive_array | |
hexupper | |
hexupper_array | |
hexupper_permissive | |
hexupper_permissive_array | |
new_encoding |
Defines a compile-time custom encoding |