Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The matches operator

Syntax

matches_expr ::= spec_expr matches pattern &&  spec_expr
               | spec_expr matches pattern ==> spec_expr

Typing

The left-hand side should be of a type that matches the pattern, while the right-hand side should have type bool. The right-hand side may reference variables bound by the pattern.

The matches_expr as a whole has type bool.

Semantics

The “matches-and” expression expr matches pat && condition is equivalent to:

match expr {
    pat => condition,
    _ => false,
}

The “matches-implies” expression expr matches pat ==> condition is equivalent to:

match expr {
    pat => condition,
    _ => true,
}