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