[][src]Crate display_bytes

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

DisplayBytes

A wrapper around a byte sequence which implements Display.

DisplayBytesConfig

Configuration builder for DisplayBytes.

FormatBase64

Formats byte sequences in Base-64.

FormatHex

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

ByteFormat

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.