LANGUAGE » RUST

Operators

Arithmetic

OperatorDescription
+Addition or unary plus
-Subtraction or unary minus
*Multiplication
/Division
%Remainder after division (modulo division)

Assignment

OperatorExampleSame as
=a = ba = b
+=a += ba = a + b
-=a -= ba = a - b
*=a *= ba = a * b
/=a /= ba = a / b
%=a %= ba = a % b
&=a %= ba = a & b
|=a %= ba = a | b
^=a %= ba = a ^ b
<<=a %= ba = a << b
>>=a %= ba = a >> b

Relational

OperatorDescription
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Logical

OperatorDescription
&&AND
||OR
!NOT

Bitwise

OperatorDescription
&AND
|OR
^XOR
~Complement
<<Shift left
>>Shift right

Ranges

OperatorExampleDescription
..0 .. 10Right-exclusive range literal (from 0 to 9)
..0 ..= 10Right-inclusive range literal (from 0 to 10)

May be used when destructuring or assigning while defining a valid range.

rust
let grade @ 0 ..= 100 = user_input else {
    return;
};
if let WebEvent::KeyPress(mychar @ 'a' ..= 'z') = pressed {
    println!("Pressed a lower case character: '{}'", mychar);
}