std-module
std::ops — operator traits and control flow
Find traits that implement supported operators, range types, and ControlFlow. Operators such as addition may be customized through traits; ordinary assignment and short-circuit logical operators cannot be overloaded this way. Expected stdout (not executed): Units(7) Common mistake: Assuming the module permits inventing arbitrary operator symbols.
Formal Syntax & Structure
rust syntaxrust
use std::ops::{Add, ControlFlow};Working Example
Example Snippetrust
fn main() { use std::ops::Add; #[derive(Debug)] struct Units(u32); impl Add for Units { type Output = Self; fn add(self, rhs: Self) -> Self { Self(self.0 + rhs.0) } } println!("{:?}", Units(2) + Units(5));}