match using "case Point2d(x,y):"
match using "case Point2d(x,y):"
Posted Jun 24, 2021 18:30 UTC (Thu) by samlh (subscriber, #56788)In reply to: match using "case Point2d(x,y):" by douglasbagnall
Parent article: New features and other changes in Python 3.10
Rust takes this a step further:
Rust's match statements and function parameter syntax are (intentionally) quite tightly aligned - they are both "patterns".
The difference is that function parameter bindings must be irrefutable (always match), while match statement arms don't have to always match.
https://doc.rust-lang.org/reference/expressions/match-exp...
> A match expression branches on a pattern. The exact form of matching that occurs depends on the pattern.
https://doc.rust-lang.org/reference/items/functions.html#...
> As with let bindings, function parameters are irrefutable patterns, so any pattern that is valid in a let binding is also valid as an argument.
https://doc.rust-lang.org/reference/patterns.html#refutab...
> A pattern is said to be refutable when it has the possibility of not being matched by the value it is being matched against. Irrefutable patterns, on the other hand, always match the value they are being matched against.
Posted Jul 1, 2021 13:02 UTC (Thu)
by bluss (guest, #47454)
[Link]
match using "case Point2d(x,y):"