Skip to content

Instantly share code, notes, and snippets.

@ioncodes
Created March 1, 2017 17:59
Show Gist options
  • Save ioncodes/64fe37737f5d1306ca8013303a7f7d7c to your computer and use it in GitHub Desktop.
Save ioncodes/64fe37737f5d1306ca8013303a7f7d7c to your computer and use it in GitHub Desktop.
convert u8 to hex
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