Skip to content

JarredAllen/hex-display

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hex-display

crates.io

An implementation of Display on a wrapper for &[u8] which provides a hex string or hexdump (see [Hex] and [HexDisplayExt]). This crate also works in no_std environments.

If alloc is present, it can also convert either output mode to a string.

Example usage

use hex_display::HexDisplayExt;

assert_eq!(
    format!("{}", [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef].hex()),
    "0123456789abcdef"
);
#[cfg(feature = "alloc")]
assert_eq!(
    [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef].to_hex_string(),
    "0123456789abcdef"
);
#[cfg(feature = "alloc")]
assert_eq!(
    [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef].to_hex_dump(),
    "00000000  01 23 45 67 89 ab cd ef                           |.#Eg....|",
);

Minimum Supported Rust Version

The MSRV is as defined in the Cargo.toml file. It may increase in minor versions, but will always remain at least a year ago.

Comparison with other crates

  • hex requires you allocate enough space for the entire string in memory, either by giving it a long enough slice or a dynamic memory allocator, and only gives hex strings, not hexdumps. It also provides decoding from a hex string.
  • faster_hex and hex_simd present similar APIs but provide SIMD-accelerated methods if you need maximal performance.
  • data_encoding can use a [core::fmt::Display] implementation to construct without preallocating, but doesn't implement hexdumps.

About

Rust display impl for byte slices which provides a hexdump

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages