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 is operator

Syntax

is_expr ::= spec_expr  is ident
          | spec_expr !is ident

Typing

The left hand side should be an expression with some enum type, and the right hand side should be an (unqualified) identifier of a variant of that enum. The is_expr has type bool.

Semantics

An is expression returns true if the left hand side matches the named variant. A !is expression returns the negation.

Example

fn test() {
    let x = Some(5);
    assert(x is Some);
    assert(x !is None);
}