Closed
Description
Boiled down, here's the problem I have:
let f: u8 = '\n' as u8;
let b: u8 = match f {
'\n' => 1,
_ => 2
};
I'm parsing some binary data and a u8
value in some cases might be an ASCII char. I'd love to be able to match against these with char literals, but the compiler complains. My actual code is more complicated and involves matching ['\\', 'x', c1, c2, ..]
(and similar patterns) against a &[u8]
slice.
Possible solutions might involve something like allowing casts in the pattern ('\n' as u8 => ...
). A more generic solution might be to just have a macro that takes a char literal and returns a u8
. So something like foo!('\n')
would expand to 10
.
Either that, or string literals à la C++11: u8'\n'
.
Metadata
Metadata
Assignees
Labels
No labels