derive-hex
derive-hex provides two small derive macros that implement hex formatting for
types that expose a to_bytes() method.
This crate is primarily meant to be used alongside the [dusk-bytes] crate
where to_bytes() is provided by the Serializable trait.
Derives
#[derive(Hex)] implements core::fmt::LowerHex ({:x} / {:#x}) and core::fmt::UpperHex ({:X} / {:#X}).
#[derive(HexDebug)] includes everything from Hex and additionally implements
core::fmt::Debug. Ordinary {:?} formatting emits lowercase hexadecimal,
while {:X?} emits uppercase hexadecimal; alternate forms add the 0x prefix.
Do not derive Hex or HexDebug for types containing secrets or other
confidential material. Both derives expose the complete serialized
representation: Hex through hexadecimal formatting such as {:x} and
HexDebug additionally through ordinary debug formatting such as {:?}.
Both derives format the output by iterating over self.to_bytes() and writing each byte as two hexadecimal digits.
Example
use HexDebug;
;
let p = IdPrefix;
assert_eq!;
assert_eq!;
assert_eq!;
// `HexDebug` also formats ordinary and flagged debug output as hex.
assert_eq!;
assert_eq!;
assert_eq!;
License
Licensed under the Mozilla Public License 2.0 (MPL-2.0).