I ran into a case using the csv crate in combination with structopt where I needed to parse a single char from an argument to use as a CSV delimiter. However, it appears that csv::StringBuilder only accepts u8 delimiters. I was surprised to see that there was no type-safe way to convert between char to u8 in the standard library. It would be nice if u8 implemented TryFrom<char>, where the conversion fails if the char value is outside of the U+0000 to U+00FF codepoint range (0-255).
An example use would look like this:
fn main() {
let success = u8::try_from('A').expect("Conversion should have succeeded");
let failure = u8::try_from('我').expect_err("Conversion should have failed");
}
I ran into a case using the
csvcrate in combination withstructoptwhere I needed to parse a singlecharfrom an argument to use as a CSV delimiter. However, it appears that csv::StringBuilder only acceptsu8delimiters. I was surprised to see that there was no type-safe way to convert betweenchartou8in the standard library. It would be nice ifu8implementedTryFrom<char>, where the conversion fails if thecharvalue is outside of the U+0000 to U+00FF codepoint range (0-255).An example use would look like this: