nu_pretty_hex/
lib.rs

1//! A Rust library providing pretty hex dump.
2//!
3//! A `simple_hex()` way renders one-line hex dump, and a `pretty_hex()` way renders
4//! columned multi-line hex dump with addressing and ASCII representation.
5//! A `config_hex()` way renders hex dump in specified format.
6//!
7//! ## Example of `simple_hex()`
8//! ```
9//! use nu_pretty_hex::*;
10//!
11//! let v = vec![222, 173, 190, 239, 202, 254, 32, 24];
12//! # #[cfg(feature = "alloc")]
13//! assert_eq!(simple_hex(&v), format!("{}", v.hex_dump()));
14//!
15//! println!("{}", v.hex_dump());
16//! ```
17//! Output:
18//!
19//! ```text
20//! de ad be ef  ca fe 20 18
21//! ```
22//! ## Example of `pretty_hex()`
23//! ```
24//! use nu_pretty_hex::*;
25//!
26//! let v = &include_bytes!("../tests/data");
27//! # #[cfg(feature = "alloc")]
28//! assert_eq!(pretty_hex(&v), format!("{:?}", v.hex_dump()));
29//!
30//! println!("{:?}", v.hex_dump());
31//! ```
32//! Output:
33//!
34//! ```text
35//! Length: 30 (0x1e) bytes
36//! 0000:   6b 4e 1a c3  af 03 d2 1e  7e 73 ba c8  bd 84 0f 83   kN......~s......
37//! 0010:   89 d5 cf 90  23 67 4b 48  db b1 bc 35  bf ee         ....#gKH...5..
38//! ```
39//! ## Example of `config_hex()`
40//! ```
41//! use nu_pretty_hex::*;
42//!
43//! let cfg = HexConfig {title: false, width: 8, group: 0, ..HexConfig::default() };
44//!
45//! let v = &include_bytes!("../tests/data");
46//! # #[cfg(feature = "alloc")]
47//! assert_eq!(config_hex(&v, cfg), format!("{:?}", v.hex_conf(cfg)));
48//!
49//! println!("{:?}", v.hex_conf(cfg));
50//! ```
51//! Output:
52//!
53//! ```text
54//! 0000:   6b 4e 1a c3 af 03 d2 1e   kN......
55//! 0008:   7e 73 ba c8 bd 84 0f 83   ~s......
56//! 0010:   89 d5 cf 90 23 67 4b 48   ....#gKH
57//! 0018:   db b1 bc 35 bf ee         ...5..
58//! ```
59
60mod pretty_hex;
61pub use pretty_hex::*;