Is there a crate for taking a string of hex specified by the user and break it out into a Vec array?
For example:
given input of string "0a1b2c3d4e5f" convert it to [0, a, 1, b, 2, c, 3, d, 4, e, 5, f]
Is there a crate for taking a string of hex specified by the user and break it out into a Vec array?
For example:
given input of string "0a1b2c3d4e5f" convert it to [0, a, 1, b, 2, c, 3, d, 4, e, 5, f]
It is trivial using the standard library (playground):
fn hex_to_bytes(s: &str) -> Option<Vec<u8>> {
if s.len() % 2 == 0 {
(0..s.len())
.step_by(2)
.map(|i| s.get(i..i + 2)
.and_then(|sub| u8::from_str_radix(sub, 16).ok()))
.collect()
} else {
None
}
}