Expand description
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.
Up to Rust 1.50, you may need to add the following to your .cargo/config.toml
to use this
library in no-std or no-alloc environments:
[unstable]
features = ["host_dep"]
From Rust 1.51, you may need to add the following to your Cargo.toml
:
[package]
resolver = "2"
§Examples
You can define a compile-time byte slice from an encoded string literal:
const HELLO_SLICE: &'static [u8] = &data_encoding_macro::hexlower!("68656c6c6f");
const FOOBAR_SLICE: &'static [u8] = &data_encoding_macro::base64!("Zm9vYmFy");
You can also define a compile-time byte array from an encoded string literal:
data_encoding_macro::hexlower_array!("const HELLO" = "68656c6c6f");
data_encoding_macro::base64_array!("const FOOBAR" = "Zm9vYmFy");
You can define a compile-time custom encoding from its specification:
const HEX: data_encoding::Encoding = data_encoding_macro::new_encoding! {
symbols: "0123456789abcdef",
translate_from: "ABCDEF",
translate_to: "abcdef",
};
const BASE64: data_encoding::Encoding = data_encoding_macro::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_
mime_ permissive - base64_
mime_ permissive_ 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