Closed
Description
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");
}