[rust-dev] ASCII character literals

Michael Neumann mneumann at ntecs.de
Wed Jan 15 06:37:03 PST 2014


Hi,

There are lots of protocols based on ASCII character representation. In 
Rust, the natural way to represent them is
by an u8 literal (optionally wrapped within std::ascii::Ascii).
What I am missing is a simple way to represent those literals in code. 
What I am doing most of the time is:

     fn read_char() -> Option<char> {
        match io.read_byte() {
          Some(b) => Some(b as char),
          None => None
       }
     }

And then use character literals in pattern matching. What I'd highly 
prefer is a way to directly repesent ASCII characters
in the code, like:

     match io.read_byte().unwrap {
         'c'_ascii => ....
        ....
     }

If macros would work in patterns, something like:

    match ... {
        ascii!('a') => ...
    }

would work for me too. Ideally that would work with range patterns as 
well, but of course an ascii_range!() macro would
do the same.

Is this useful to anyone?

Regards,

     Michael


More information about the Rust-dev mailing list