Expand description
Human-readable display of byte sequences.
Supports printing of both UTF-8 and ASCII-only sequences.
For easy usage, see the free functions display_bytes()
and display_bytes_string()
in this crate. For more control over formatting, see the statics in this crate or build
an instance of DisplayBytesConfig
yourself.
extern crate display_bytes;
use display_bytes::{display_bytes, display_bytes_string};
fn main() {
let bytes = b"Hello, world!\x89\x90\xAB\xCD";
println!("{:?}", bytes);
println!("{}", display_bytes(bytes));
assert_eq!(display_bytes_string(bytes),
"Hello, world! {{ 89 90 AB CD }} ");
}
Structs§
- Display
Bytes - A wrapper around a byte sequence which implements
Display
. - Display
Bytes Config - Configuration builder for
DisplayBytes
. - Format
Base64 - Formats byte sequences in Base-64.
- Format
Hex - Formats bytes in hexadecimal pairs (
00 - FF
).
Constants§
- BASE64_
ASCII - Prints byte sections as Base-64 wrapped in
{{ }}
. Prints only ASCII sequences. - BASE64_
UTF8 - Prints byte sections as Base-64 wrapped in
{{ }}
. Prints all valid UTF-8 strings. - DEFAULT_
HEX - Default hexadecimal byte format used by this crate.
- HEX_
ASCII - Prints byte sections with hexadecimal bytes wrapped in
{{ }}
. Prints only ASCII sequences. - HEX_
UTF8 - Prints byte sections with hexadecimal bytes wrapped in
{{ }}
. Prints all valid UTF-8 strings.
Traits§
- Byte
Format - Formats byte sequences in human-readable representations.
Functions§
- display_
bytes - Wrap a byte slice in an adapter which implements
Display
. - display_
bytes_ string - Attempt to convert the byte slice to a string, or else format it to a string using the default
DisplayBytesConfig
.