pub fn decode(dst: &mut [u8], src: &[u8]) -> (usize, Option<Error>)Expand description
decode decodes src into decoded_len(src.len()) bytes, returning the actual number of bytes written to dst.
decode expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, decode returns the number of bytes decoded before the error.
Examples found in repository?
examples/hex.rs (line 31)
27fn example_decode() {
28 let src = b"48656c6c6f20476f7068657221";
29
30 let mut dst = vec![0; hex::decoded_len(src.len())];
31 let (n, err) = hex::decode(&mut dst, src);
32 if err.is_some() {
33 panic!("{}", err.unwrap());
34 }
35
36 println!("{}", String::from_utf8_lossy(&dst[..n]));
37
38 // Output:
39 // Hello Gopher!
40}