Operator Precedence

All operators in Rhai has a precedence indicating how tightly they bind.

A higher precedence binds more tightly than a lower precedence, so * and / binds before + and - etc.

When registering a custom operator, the operator’s precedence must also be provided.

The following precedence table shows the built-in precedence of standard Rhai operators:

CategoryOperatorsBindingPrecedence (0-255)
Logic and bit masks||, |, ^left30
Logic and bit masks&&, &left60
Comparisons==, !=left90
Comparisons>, >=, <, <=left130
Ranges.., ..=left140
Arithmetic+, -left150
Arithmetic*, /, %left180
Bit-shifts<<, >>left210
Unary operators+, -, !righthighest
Object field access., ?.righthighest