hex_to_string

Function hex_to_string 

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

Converts a hexadecimal string to a UTF-8 string.

This function takes a hexadecimal string and attempts to convert it to a UTF-8 string. The input hex string must have an even number of characters and contain only valid hexadecimal digits. The resulting bytes must form a valid UTF-8 sequence.

§Arguments

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

§Returns

A Result containing either:

  • Ok(String): The UTF-8 string representation of the input hexadecimal.
  • Err(String): An error message if the input is invalid or the bytes are not valid UTF-8.

§Example

let hex = "48656c6c6f";
let string = byteutils::hex_to_string(hex).unwrap();
assert_eq!(string, "Hello");