Skip to main content

from_utf8_bytes

Function from_utf8_bytes 

Source
pub fn from_utf8_bytes(data: &[u8]) -> Result<String>
Expand description

Converts UTF-8 bytes to a string.

§Arguments

  • data - The UTF-8 encoded bytes

§Returns

The decoded string, or an error if the bytes are not valid UTF-8

§Example

use bsv_rs::primitives::encoding::from_utf8_bytes;

assert_eq!(from_utf8_bytes(&[72, 101, 108, 108, 111]).unwrap(), "Hello");
assert!(from_utf8_bytes(&[0xFF, 0xFE]).is_err()); // Invalid UTF-8