hex_to_bytes

Function hex_to_bytes 

Source
pub fn hex_to_bytes(hex: &str) -> Result<Vec<u8>, String>
Expand description

Converts a hexadecimal string to its byte representation.

This function takes a string slice containing a hexadecimal representation and returns a Vec containing the corresponding bytes. The input string must have an even number of characters and contain only valid hexadecimal digits (0-9, a-f, A-F).

§Arguments

  • hex - A string slice containing the hexadecimal representation to convert.

§Returns

A Result containing either:

  • Ok(Vec): The byte representation of the input hexadecimal string.
  • Err(String): An error message if the input is invalid.

§Example

let bytes = byteutils::hex_to_bytes("0fff0080").unwrap();
assert_eq!(byteutils::hex_to_bytes("0fff0080").unwrap(), vec![15, 255, 0, 128]);