Ergonomic opposite of `matches!`

Yet another alternative, as pointed out in this prelude discussion (which also mentions a previous internals thread):

use std::ops::Not;
if matches!(val, pattern).not() {
   ...
}

Perl and Ruby have this and I do agree it is handy in the right circumstances. But I also feel unless blocks become a liability due to confusion once combined with else blocks/chains. It could be restricted to the non-chained case, thought that would likely make it harder to justify a new keyword.

7 Likes