-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(aya-log): print &[u8] using full width #1008
Conversation
✅ Deploy Preview for aya-rs-docs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
aya-log/src/lib.rs
Outdated
match last_hint.map(|DisplayHintWrapper(dh)| dh) { | ||
Some(DisplayHint::LowerHex) => Ok(LowerHexDebugFormatter::format(self)), | ||
Some(DisplayHint::UpperHex) => Ok(UpperHexDebugFormatter::format(self)), | ||
Some(DisplayHint::LowerHex) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this change would belong to *HexDebugFormatter and not inline here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Let's make these changes here:
Lines 208 to 219 in ab000ad
impl<T> Formatter<&[T]> for LowerHexDebugFormatter | |
where | |
T: LowerHex, | |
{ | |
fn format(v: &[T]) -> String { | |
let mut s = String::new(); | |
for v in v { | |
let () = core::fmt::write(&mut s, format_args!("{v:x}")).unwrap(); | |
} | |
s | |
} | |
} |
Lines 232 to 243 in ab000ad
impl<T> Formatter<&[T]> for UpperHexDebugFormatter | |
where | |
T: UpperHex, | |
{ | |
fn format(v: &[T]) -> String { | |
let mut s = String::new(); | |
for v in v { | |
let () = core::fmt::write(&mut s, format_args!("{v:X}")).unwrap(); | |
} | |
s | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Rust has a formatting option of "print as many zeroes as needed", so it's not really possible to do this in generic context. And since specialization like in C++ does not exist in (stable) Rust (yet?), I had to hardcode the width of 2 somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean but UpperHexDebugFormatter (perhaps misnamed) is only used for for impl Format for &[u8]
so with your change now it becomes dead code. So we might as well do the change there?
c07d98d
to
e2bfbab
Compare
e2bfbab
to
851d3ef
Compare
I've done what #1008 (comment) suggested and added a test as well |
851d3ef
to
a46f09f
Compare
Rebased this with regenerated API. @alessandrod does this require further changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great now, thanks!
Otherwise you cannot distinguish
&[1u8, 0u8]
from&[0x10u8]
(they both become10
)