5 ms·
Why are nullable Rust pointers checked with "is_null" and not pattern-matched against null vs. non-null?
by Peaker 12y ago
Why are nullable Rust pointers checked with "is_null" and not pattern-matched against null vs. non-null?
- pcwalton 12y agoWe don't have pattern matching for unsafe pointers in the language. Nobody has asked for it, probably because unsafe pointers aren't used enough for it to matter.
- azth 12y ago> Nobody has asked for it, probably because unsafe pointers aren't used enough for it to matter. Which is a good thing!
- ben0x539 12y agoYou could argue that we shouldn't have nullable raw pointers at all and build the Option type into the language, but otherwise I don't think pattern matching on nullable pointers buys you much since you don't need to extract the pointer value for the non-null case and you'd just be using the match expression as a glorified if-else.
- Peaker 12y agoHaving raw pointers be represented as simple pointers, but accessed as if they were wrapped with an Option (or equivalent) could be nice. I agree that if the raw pointer is directly usable whether or not it may be null, then the pattern matching is almost pointless.