This repository has been archived by the owner on May 18, 2022. It is now read-only.
Use custom_debug_derive instead of the Hex/HexSlice wrappers #66
Labels
area: utils
Code Area: Utilities and scaffolding used throughout the project
help wanted
Call for participation: Help is requested to fix this issue
status: needs code
An implementation or a bugfix need to be written
type: cleanup
Code cleanup that doesn't affect functionality
Hex
wraps a value that implementsfmt::LowerHex
, and uses that implementation whenfmt::Debug
-printed ({:?}
).HexSlice
takes any type implementingAsRef<[u8]>
and prints it as hexadecimal when printed viafmt::Debug
/{:?}
.These types make it easy to quickly customize how fields are printed by wrapping them in
Hex
/HexSlice
, which is way less work than implementingfmt::Debug
by hand (and less error-prone, because#[derive(Debug)]
will never forget any fields, unlike a hand-rolled impl).The problem with them is that they conflate data with behavior by being embedded in the
struct
/enum
definition itself instead of being part of an impl or being attributes. It takes an extra step to access a value behind them, too.I think it would be a good idea to use
custom_debug_derive
instead. For that, we should add ahex
andhex_slice
function toutils
that do whatHex
andHexSlice
currently do, and then use#[debug(with = "utils::hex")]
on the fields that are now wrapped inHex
and#[debug(with = "utils::hex_slice")]
on fields that useHexSlice
.That crate also supports specifying a format string, which is going to be quite a bit less efficient than what we have now, so it should only be used when necessary.
The text was updated successfully, but these errors were encountered: