Expand description
Functions for encoding sequences of bytes into base 16 hex encoding.
Base 16 encoding is an encoding scheme that uses a 16 character ASCII alphabet for encoding arbitrary octets.
This crate offers encoders that:
- Allocate and return a
String:try_encode. - Encode into an already allocated
String:try_encode_into. - Encode into a
core::fmt::Write:format_into. - Encode into a
std::io::Write:write_into.
§Examples
let data = b"Artichoke Ruby";
let mut buf = String::new();
scolapasta_hex::try_encode_into(data, &mut buf)?;
assert_eq!(buf, "4172746963686f6b652052756279");This module also exposes an iterator:
use scolapasta_hex::Hex;
let data = "Artichoke Ruby";
let iter = Hex::from(data);
assert_eq!(iter.collect::<String>(), "4172746963686f6b652052756279");§no_std
This crate is no_std compatible when built without the std feature. This
crate optionally depends on alloc when the alloc feature is enabled.
When this crate depends on alloc, it exclusively uses fallible allocation
APIs. The APIs in this crate will never abort due to allocation failure or
capacity overflows. Note that writers given to format_into and
write_into may have abort on allocation failure behavior.
§Crate features
All features are enabled by default.
- std - Enables a dependency on the Rust Standard Library. Activating
this feature enables APIs that require
std::io::Write. Activating this feature also activates the alloc feature. - alloc - Enables a dependency on the Rust
alloccrate. Activating this feature enables APIs that requirealloc::string::String.
Structs§
Functions§
- escape_
byte - Map from a
u8to a hex encoded string literal. - format_
into - Write hex-encoded octets into the given
fmt::Write. - try_
encode alloc - Encode arbitrary octets as base16. Returns a
String. - try_
encode_ into alloc - Encode arbitrary octets as base16 into the given
String. - write_
into std - Write hex-encoded octets into the given
io::Write.