Operators in Rust are symbolic tokens that instruct the compiler to perform specific mathematical, logical, relational, or bitwise computations. Unlike many systems programming languages, Rust implements most operators as syntactic sugar for trait methods defined in theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
std::ops and std::cmp modules. This architecture allows operators to be overloaded for custom types by implementing the corresponding traits.
Arithmetic Operators
Arithmetic operators perform standard mathematical computations and map directly to traits instd::ops. For integer types, if an operation overflows in debug mode, Rust will panic; in release mode, it performs two’s complement wrapping. Floating-point types (f32, f64) follow IEEE 754 rules and will evaluate to infinity (inf or -inf) upon overflow, without panicking or wrapping in either debug or release mode.
+: Addition (std::ops::Add)-: Subtraction (std::ops::Sub)*: Multiplication (std::ops::Mul)/: Division (std::ops::Div)%: Remainder (std::ops::Rem)-: Negation (std::ops::Neg)
Bitwise and Eager Logical Operators
Bitwise operators manipulate the individual bits of integer types. Additionally, the& and | operators are implemented for bool types to perform eager (non-short-circuiting) logical evaluation. They map to traits in std::ops. The ! operator is overloaded to function as a bitwise NOT when applied to integers.
&: Bitwise AND / Eager Logical AND (std::ops::BitAnd)|: Bitwise OR / Eager Logical OR (std::ops::BitOr)^: Bitwise XOR (std::ops::BitXor)!: Bitwise NOT (std::ops::Not)<<: Left Shift (std::ops::Shl)>>: Right Shift (std::ops::Shr)
Logical Operators
Logical operators evaluate boolean expressions. The&& and || operators utilize short-circuit evaluation. Because short-circuiting requires controlling control flow, && and || cannot be overloaded and do not have backing traits. The ! operator functions as a logical NOT when applied to booleans.
&&: Logical AND (Short-circuiting)||: Logical OR (Short-circuiting)!: Logical NOT (std::ops::Not)
Comparison (Relational) Operators
Comparison operators evaluate the relationship between two values, returning a boolean. They map to traits instd::cmp.
==: Equal to (std::cmp::PartialEq)!=: Not equal to (std::cmp::PartialEq)<: Less than (std::cmp::PartialOrd)>: Greater than (std::cmp::PartialOrd)<=: Less than or equal to (std::cmp::PartialOrd)>=: Greater than or equal to (std::cmp::PartialOrd)
Assignment and Compound Assignment Operators
The basic assignment operator (=) binds a value to a memory location or updates a mutable variable. Compound assignment operators combine an arithmetic or bitwise operation with assignment. Compound operators map to traits in std::ops suffixed with Assign. They mutate the left-hand operand in place and do not return a value (they evaluate to the unit type ()).
=: Basic Assignment+=,-=,*=,/=,%=: Arithmetic Compound Assignment&=,|=,^=,<<=,>>=: Bitwise Compound Assignment
Type, Memory, and Access Operators
Rust includes specific operators for memory management, pointer manipulation, collection access, and type conversion.&: Shared borrow / Reference creation&mut: Mutable borrow / Mutable reference creation*: Dereference (std::ops::Derefandstd::ops::DerefMut)[]: Array/Slice indexing (std::ops::Indexandstd::ops::IndexMut)as: Safe primitive type casting
Control Flow and Structural Operators
These operators handle structural generation or control flow propagation at the syntax level.?: Error propagation operator. UnwrapsResult/Optionor returns early onErr/None(std::ops::Try)...: Exclusive range (std::ops::Range)..=: Inclusive range (std::ops::RangeInclusive)
Master Rust with Deep Grasping Methodology!Learn More





