pub fn bytes_to_string(bytes: &[u8]) -> Result<String, String>Expand description
Converts a byte slice to a UTF-8 string.
This function takes a slice of bytes and attempts to convert it to a UTF-8 string. If the bytes do not represent valid UTF-8 data, an error is returned.
§Arguments
bytes- A slice of bytes to convert to a string.
§Returns
A Result containing either:
- Ok(String): The UTF-8 string representation of the input bytes.
- Err(String): An error message if the bytes are not valid UTF-8.
§Example
let bytes = "Hello".as_bytes();
let string = byteutils::bytes_to_string(bytes).unwrap();
assert_eq!(string, "Hello");