Can I define my own operator symbol in Rust? If so, how?
For example, a + b
is equivalent to a.add(b)
. Can I define a symbol like ~
so that a ~ b
is equivalent to a.myop(b)
for some method myop
? (I'm assuming ~
has no other meaning in Rust which I think is true.)
Of course I would expect this operator to be implemented the same way operators in std::ops are, so an implementation would look like:
impl<T> MyOp<T> for MyStruct {
type Output = x;
fn myop(self, other: T) -> x {
...
}
}
Also, if this is possible what symbols are allowed?