bytes_to_string

Function bytes_to_string 

Source
pub fn bytes_to_string(value: &[u8]) -> String
Expand description

Efficient bytes to string conversion - zero-copy for valid UTF-8

Uses std::str::from_utf8() for zero-copy conversion when the input is valid UTF-8, falling back to lossy conversion otherwise.

ยงExamples

use feedparser_rs::util::text::bytes_to_string;

let valid_utf8 = b"Hello, world!";
assert_eq!(bytes_to_string(valid_utf8), "Hello, world!");

let invalid_utf8 = &[0xFF, 0xFE, 0xFD];
let result = bytes_to_string(invalid_utf8);
assert!(!result.is_empty()); // Lossy conversion succeeded