pub fn decode(
input: &[u8],
encoding: &'static Encoding,
) -> Result<String, EncodingError>Expand description
Decode raw bytes using a known encoding.
Returns the decoded UTF-8 string. If the input is already valid UTF-8 and
encoding is UTF-8, this avoids copying via Cow.
§Errors
Returns EncodingError::MalformedInput if the decoder encounters
bytes that cannot be mapped to Unicode and the encoding does not use
a replacement character (in practice, encoding_rs always replaces
unmappable bytes, so this is defensive).
§Example
use fhp_encoding::decode;
use encoding_rs::UTF_8;
let text = decode(b"Hello, world!", UTF_8).unwrap();
assert_eq!(text, "Hello, world!");