-
-
Save csknk/6e4b087d485f6f20371aa9d1cda4d8c4 to your computer and use it in GitHub Desktop.
Revisions
-
csknk renamed this gist
Jul 3, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rust-play created this gist
Jul 3, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ use std::fmt; fn main() -> Result<(), &'static str> { let b = vec![0x64, 0x61, 0x76, 0x65]; println!("{}", b.to_hex()); Ok(()) } trait ToHex { fn to_hex(&self) -> String; } impl<T: fmt::LowerHex> ToHex for T { fn to_hex(&self) -> String { format!("{:x}", self) } } impl ToHex for [u8] { fn to_hex(&self) -> String { use core::fmt::Write; let mut ret = String::with_capacity(2 * self.len()); for ch in self { write!(ret, "{:02X}", ch).expect("writing to string"); } ret } }