I am trying to convert a vector of ASCII bytes into a rust string. I found the std::str::from_utf8()
function, that should be able to handle all ASCII strings. For some reason it cannot read the copyright symbol, as shown in this code sample:
let buf = vec![0xA9, 0x41, 0x52, 0x54]; //©ARTprintln!("{}", match std::str::from_utf8(&buf) { Ok(x) => x, Err(x) => { println!("ERROR: {}", x);"failed" } });// > ERROR: invalid utf-8 sequence of 1 bytes from index 0
According to https://www.ascii-code.com/CP1252/1690xA9
is a valid ASCII character, and according to https://www.compart.com/en/unicode/U+00A9 also a valid UTF-8 character.
I also tried String::from_utf8_lossy()
, but that gave me �ART
as a result, which is not what the string should be.
Am I missing something here or is this a bug with the way rust handles ASCII?