In Rust it\'s possible to get UTF-8 from bytes by doing this:
if let Ok(s) = str::from_utf8(some_u8_slice) {
println!(\"example {}\", s);
}
You can either:
Construct it yourself by using the strict UTF-8 decoding which returns an error indicating the position where the decoding failed, which you can then escape. But that's inefficient since you will decode each failed attempt twice.
Try 3rd party crates which provide more customizable charset decoders.