Skip to main content

hex_decode_vec

Function hex_decode_vec 

Source
pub fn hex_decode_vec(src: &[u8]) -> Result<Vec<u8>, Error>
Available on crate feature alloc only.
Expand description

Decodes the complete input into a new vector, accepting either letter case.

Available with alloc. The result owns exactly src.len() / 2 decoded bytes, independently of the input. Empty input produces an empty vector. The same strict ASCII grammar as hex_decode applies: no prefixes, whitespace or separators. Use hex_decode_vec_with_case to restrict letter case.

§Errors

Returns Error::OddLength for odd input, before allocating output. Even input is checked for Error::InvalidChar after allocation, so malformed even-length input can allocate before its first invalid byte is reported.

There is no input-size limit or recoverable allocation-error result. The vector uses the allocator’s normal error handling. Apply an application limit before calling when necessary, or use hex_decode with reusable storage.

§Examples

assert_eq!(faster_hex::hex_decode_vec(b"00aBff")?, [0, 0xab, 0xff]);
assert!(faster_hex::hex_decode_vec(b"0x01").is_err());