Function decode

Source
pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, FromHexError>
Available on crate feature alloc only.
Expand description

Decodes a hex string into raw bytes.

Only lowercase characters are valid in the input string (e.g. f9b4ca).

§Errors

This function returns an error if the input is not an even number of characters long or contains invalid hex characters.

§Example

assert_eq!(
    lowercase_hex::decode("48656c6c6f20776f726c6421"),
    Ok("Hello world!".to_owned().into_bytes())
);

assert_eq!(lowercase_hex::decode("123"), Err(lowercase_hex::FromHexError::OddLength));
assert!(lowercase_hex::decode("foo").is_err());