Conversation
src/lib.rs
Outdated
| impl<'a, W: Width + Debug, I: Implementation> Debug for Digest<'a, W, I> { | ||
| fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| f.debug_struct("Digest") | ||
| .field("value", &self.value) |
There was a problem hiding this comment.
IMO, this should be formatted as hex w/ constant char width based on W.
There was a problem hiding this comment.
I think that's a good idea, but idk how to make the width based on the max width of W, since there isn't a trait (at least in std), with const BITS: usize. Here is my current implementation:
let width = "0x".len() + (u16::BITS / 8 * 2) as usize;
let value = &self.value;
f.debug_struct("Digest")
.field("value", &format_args!("{value:#0width$x?}"))
.finish()But as you can see this currently hard-codes u16, since W::BITS isn't valid code. One solution might be to add it to the Width trait, and implement it manually for the number types.
There was a problem hiding this comment.
impl<'a, W: Width + Debug + LowerHex, I: Implementation> Debug for Digest<'a, W, I> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Digest")
.field("value", &format_args!("0x{:0w$x}", self.value, w = size_of::<W>() * 2))
.finish()
}
}^ this should work
There was a problem hiding this comment.
Oh yeah, I forgot that we can use size_of for this. Also the +2 is needed because "0x" is included in the length. I added a commit which changes to hex.
Closes #129
This implementation only shows the
valuefield and not the info about the CRC. We could technically show the CRC config, but I don't think it would be that useful.