Created
March 1, 2017 17:59
-
-
Save ioncodes/64fe37737f5d1306ca8013303a7f7d7c to your computer and use it in GitHub Desktop.
convert u8 to hex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
struct ByteBuf<'a>(&'a [u8]); | |
impl<'a> fmt::LowerHex for ByteBuf<'a> { | |
fn fmt(&self, fmtr: &mut fmt::Formatter) -> Result<(), fmt::Error> { | |
for byte in self.0 { | |
try!(fmtr.write_fmt(format_args!("{:02x}", byte))); | |
} | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment