Hexd
A simple, configurable and dependency-free hexdump library for Rust.
Installation
cargo add hxd
Examples
Any slice of bytes can be dumped with a single line:
use AsHexd;
let msg = b"Hello, world! Hopefully you're seeing this in hexd...";
msg.hexd.dump;
// 00000000: 4865 6C6C 6F2C 2077 6F72 6C64 2120 486F |Hello, world! Ho|
// 00000010: 7065 6675 6C6C 7920 796F 7527 7265 2073 |pefully you're s|
// 00000020: 6565 696E 6720 7468 6973 2069 6E20 6865 |eeing this in he|
// 00000030: 7864 2E2E 2E |xd... |
Any iterator that yields bytes can be consumed and dumped as well:
use IntoHexd;
let msg = b"Hello, world! Hopefully you're seeing this in hexd...";
let iter = msg.into_iter.map;
iter.hexd.dump;
// 00000000: 4966 6D6D 702D 2178 7073 6D65 2221 4970 |Ifmmp-!xpsme"!Ip|
// 00000010: 7166 6776 6D6D 7A21 7A70 7628 7366 2174 |qfgvmmz!zpv(sf!t|
// 00000020: 6666 6A6F 6821 7569 6A74 216A 6F21 6966 |ffjoh!uijt!jo!if|
// 00000030: 7965 2F2F 2F |ye/// |
Options are configurable via a fluent interface:
use ;
let v = .;
v.hexd
.grouped
.uppercase
.range
.relative_offset
.dump;
// 00ff0040: 454647 48494a4b 4c4d4e4f | EFGHIJKLMNO|
// 00ff0050: 50515253 54555657 58595a5b 5c5d5e5f |PQRSTUVWXYZ[\]^_|
// 00ff0060: 60616263 64656667 68696a6b 6c6d6e6f |`abcdefghijklmno|
// 00ff0070: 70717273 74757677 78797a |pqrstuvwxyz |
Hexdumps can be written to a variety of targets out of the box:
use ;
use ;
let v = vec!;
let f = new
.write
.open
.unwrap;
let tcp_stream = connect.unwrap;
v.hexd.dump;
v.hexd.dump_err;
v.hexd.;
v.hexd.;
v.hexd.dump_into.unwrap;
v.hexd.dump_io.unwrap;
All primitive integer types can be dumped with sensible display defaults:
use ;
vec!.as_hexd.dump;
// 00000000: 2061 2061 2061 2061 2061 2061 2061 2061 | a a a a a a a a|
vec!.as_hexd_be.dump;
// 00000000: 7FA06120 7FA06120 7FA06120 7FA06120 |..a ..a ..a ..a |
vec!.as_hexd_le.dump;
// 00000000: 2061A07F00F30F00 2061A07F00F30F00 | a...... a......|
vec!.as_hexd_be.dump;
// 00000000: 00 00 00 00 00 00 00 00 00 00 00 00 7F A0 61 20 |..............a |