Rust operators
From wikinotes
Arithmetic
+ // add - // subtract / // divide * // multiplyOperator overloading is supported in rust, by implementing
std::ops
traits.
It does not need to be generic.struct Num { val i32, } impl ops::Add<T> for Num { type Output = T; fn add(self, _rhs: T) -> T { // ... } } let num = Num{val: 123}; num + 1;
Result Operators
?
- ok-val assign to `bar`
- err-val return-early with Err(Err-val)
fn foo() -> Result<_, _> { let bar = get_result()?; }