-
Notifications
You must be signed in to change notification settings - Fork 57
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
Display wrapper to get hex data #8
Comments
A more elegant solution would be to use a trait instead of a wrapper trait Hexable {
fn fmt_lower(&self, f: &mut fmt::Formatter) -> fmt::Result;
fn fmt_upper(&self, f: &mut fmt::Formatter) -> fmt::Result;
}
impl<H: Hexable> fmt::LowerHex for H {
// ...
} (one might repurpose the I will make a PR for this 😊 |
Update: the above is blocked on #37 and/or specialization. impl fmt::LowerHex for dyn ToHex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.encode_hex())
}
}
and impl<T: ToHex> fmt::LowerHex for T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.encode_hex())
}
}
|
@Luro02 yes that would probably not work even with the specialization that is currently in the nightly compiler. That's because of orphan rules. This is why I've proposed the wrapper struct (a NewType). You can add a helper method for |
@tailhook the problems with the orphan rule seem to be two things:
The problem of overlapping implementations would be solved through specialization (the Specialization works through choosing the most specific implementation of a trait (e.g. A default implementation would be the least specific implementation, so any other impl will be preferred over this crates impl. It might cause conflicts, if someone tries to import two different traits, which both have a default impl of the same trait, but in such a case the user should just cast the type to a trait object ( So I think it will be possible to do this in the future 😊, but for now having a wrapper type would be useful too. |
Hi,
It would be useful to be able to do something like:
This would allow hexlify things without creating temporary buffers.
What do you think?
The text was updated successfully, but these errors were encountered: