[rust-dev] ASCII character literals

Michael Neumann mneumann at ntecs.de
Wed Jan 15 07:26:31 PST 2014


Am 15.01.2014 16:23, schrieb Evan G:
> I'm not weighing in on whether this is something rust should do or 
> not, but we could mimic the 16i, 10u numeric literal system to achieve 
> this in syntax. An ascii literal would have a suffix, for example 'x'a 
> or 'x'u to explicitly specify unicode (which would still be the 
> default). This could probably work for string literals too.

Something like 'x'a would be very nice to have!

Regards,

   Michael

>
>
> On Wed, Jan 15, 2014 at 8:37 AM, Michael Neumann <mneumann at ntecs.de 
> <mailto:mneumann at ntecs.de>> wrote:
>
>     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
>     _______________________________________________
>     Rust-dev mailing list
>     Rust-dev at mozilla.org <mailto:Rust-dev at mozilla.org>
>     https://mail.mozilla.org/listinfo/rust-dev
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140115/9130fd50/attachment.html>


More information about the Rust-dev mailing list