I would like to be able to point at a direction by using a match condition statement (see the playground code here). I wonder what I am doing wrong, could you point my error in the reasoning on the patterns and the way this matching should work ?
Patterns don’t support open-ended ranges, but you can use constants for endpoints, like
std::i32::MIN...0. Note that pattern ranges are inclusive, so this also matches
0. If you don’t want that, use
Another caveat is that rustc doesn’t know how to check exhaustive number matches. So even if you think you’ve covered everything, you’re going to need a final catch-all match – like
_ => unreachable!().
Thanks a lot for your extensive response !
Is there a way to avoid citing the type in the
You can also use match guards:
(0, y) if y <= 0 => println!("N")
Thank you for your help guys !
I’m sorry, but I’m confused; I thought that ranges were defined as
.. not as
... is an old syntax for inclusive range
..= (where end of the range equals the highest number).
.. is for exclusive range (where highest number matched is less than the range end).