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

Appendix B: Operators

The table runs from loose binding to tight binding. Parentheses override this order.

LevelOperatorsAssociation
Assignment=, +=, -=, *=, /=, %=, **=, .= and compound bit, shift, coalesce, and Boolean assignmentsright
Coalesce??right
Boolean or`
Boolean and&&left
Comparison==, !=, <, <=, >, >=, <=>none
Typeis, as, ?asnone
Pipeline`>`
Concatenation.left
Bitwise or``
Bitwise xor^left
Bitwise and&left
Shift<<, >>left
Addition+, -left
Multiplication*, /, %left
Prefix!, ~, unary + and -, prefix ++ and --right
Exponentiation**right
Postfixcalls, indexing, ->, ?->, ::, postfix ++ and --left

Comparisons and type operators do not chain. Write the intended grouping or combine complete comparisons with &&.

Collection and language operations

Several operations use construct syntax and do not belong in the precedence table:

  • length!($value) returns the length of a string or array.
  • contains!($array, $value) and contains_key!($array, $key) search arrays.
  • remove!($array, $key) removes and returns an entry.
  • swap_remove!($vec, $index) removes and returns an item without preserving vec order.
  • clone!($object, property: $value) clones an object with changed properties.
  • drop!($resource) ends ownership immediately and reports a leak.
  • debug!($value) prints a bounded structural view with its source location.
  • require! and require_once! load source files.

The compiler checks these forms by their own rules.