|
The example of match usage is really poor. From the looks of it there is no "pattern matching" going on at all here. I don't know the syntax, but even something like this would be a better demonstration: let computed_key = match (key.len() > self.block_size, key.len() < self.block_size) {
(true, false) => self.zero_pad(self.hash(key).digest),
(false, true) => self.zero_pad(key),
(false, false) => key
}
At least there is some matching here, unlike in the original example. But in real world this should be if..else if..else statement, not match - the latter being used makes no sense if there is no matching going on. In Erlang there is an if statement, which is a 'case' (equivalent of match here) but with matches taken out and only guards allowed - that's what would fit here, but I doubt Rust has something like this.Also, does the compiler complain about my example above being not exhaustive? I think in OCaml it would, which is sometimes nice. |
Oh, but it does! There's the cond! macro: