Hacker News new | ask | show | jobs
by masklinn 4685 days ago
> Also, does the compiler complain about my example above being not exhaustive?

Yes, although the error message isn't very good:

    crypto.rs:55:23: 59:5 error: non-exhaustive patterns: true not covered
    crypto.rs:55     let computed_key = match (key.len() > self.block_size, key.len() < self.block_size) {
    crypto.rs:56         (true, false) => self.zero_pad(self.hash(key).digest),
    crypto.rs:57         (false, true) => self.zero_pad(key),
    crypto.rs:58         (false, false) => key
    crypto.rs:59     };
    error: aborting due to previous error
And technically that's not a good thing, since (true, true) is not possible considering the input.
1 comments

it should be expressed with conditionals anyway.

    match key.len() {
    k if k > self.block_size => ..
    k if k < ... => ..
    k  => ...
or even

    match key.cmp(self.block_size) {
    Equal => ..
    Greater => ..
    Less => ...
Absolutely.
Thanks for the tip!