Module display

Expand description

Helpers for displaying bytes as hex strings.

This module provides a trait for displaying things as hex as well as an implementation for &[u8].

For arrays and slices we support padding and precision for length < 512 bytes.

§Examples

use hex_conservative::DisplayHex;

// Display as hex.
let v = vec![0xde, 0xad, 0xbe, 0xef];
assert_eq!(format!("{}", v.as_hex()), "deadbeef");

// Get the most significant bytes.
let v = vec![0x01, 0x23, 0x45, 0x67];
assert_eq!(format!("{0:.4}", v.as_hex()), "0123");

// Padding with zeros
let v = vec![0xab; 2];
assert_eq!(format!("{:0>8}", v.as_hex()), "0000abab");

Macros§

fmt_hex_exact
Format known-length array as hex.
impl_fmt_traits
Adds core::fmt trait implementations to type $ty.

Structs§

DisplayArray
Displays byte array as hex.
DisplayByteSlice
Displays byte slice as hex.

Traits§

DisplayHex
Extension trait for types that can be displayed as hex.