Skip to content
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

Implement fmt::LowerHex and fmt::UpperHex #17

Closed
cchudant opened this issue Oct 22, 2018 · 2 comments
Closed

Implement fmt::LowerHex and fmt::UpperHex #17

cchudant opened this issue Oct 22, 2018 · 2 comments

Comments

@cchudant
Copy link

cchudant commented Oct 22, 2018

https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html
https://doc.rust-lang.org/nightly/core/fmt/trait.UpperHex.html

it would be great to directly display u8 slices to the console like this:

let data: &[u8] = ...;
println!("{:x}", data);

because we currently have to do this:

let mut s = String::new();
data.write_hex(&mut s).unwrap();
println!("{}", s);

which isn't great

@LukasKalbertodt
Copy link
Contributor

Hi there! :)

Unfortunately, what you suggest is not possible. We can't add an impl UpperHex for &[u8] in this crate due to so called orphan rules. I.e.: either the trait or the type of an impl has to be defined in the same crate as the impl itself.

To work around this, one could have a newtype which wraps a slice. This is what is suggested in #8. So I think this issue can be closed in favor of #8.

@cchudant
Copy link
Author

Oh ok, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants