-
-
Save niksaak/91f176af470093bf3b15c9e5af5ba466 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains 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::str; | |
fn main() { | |
let b = "67e5504410b1426f9247bb680e5fe0c8"; | |
let mut bytes = [0u8; 16]; | |
for (dest, chunk) in bytes.iter_mut().zip(b.as_bytes().chunks(2)) { | |
let s = match str::from_utf8(chunk) { | |
Ok(v) => v, | |
Err(e) => panic!("Invalid UTF-8 sequence: {}", e), | |
}; | |
match u8::from_str_radix(s, 16) { | |
Ok(byte) => *dest = byte, | |
Err(..) => {}, | |
} | |
} | |
println!("{:?}", bytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment