I know we can implement traits that override the standard arithmetic operators. Can we also create our own traits that overload custom operators? I have come to really enjoy Haskell's system for defining operators.
Asked
Active
Viewed 4,396 times
1 Answers
13
No, per the manual the only operators that can be overloaded are:
!
— Bitwise or logical complement!=
— Nonequality comparison%
— Arithmetic remainder%=
— Arithmetic remainder and assignment&
— Bitwise AND&=
— Bitwise AND and assignment*
— Arithmetic multiplication*=
— Arithmetic multiplication and assignment+
— Arithmetic addition+=
— Arithmetic addition and assignment-
— Arithmetic negation-
— Arithmetic subtraction-=
— Arithmetic subtraction and assignment/
— Arithmetic division/=
— Arithmetic division and assignment<<
— Left-shift<<=
— Left-shift and assignment<
— Less than comparison<=
— Less than or equal to comparison==
— Equality comparison>
— Greater than comparison>=
— Greater than or equal to comparison>>
— Right-shift>>=
— Right-shift and assignment^
— Bitwise exclusive OR^=
— Bitwise exclusive OR and assignment|
— Bitwise OR|=
— Bitwise OR and assignment
-
Do you know if there are any plans to add this functionality? Or, plans to never add this functionality? Thanks – MFlamer May 25 '13 at 00:17
-
I would assume (and I have a vague recollection) that Graydon (Rust's BFDL) dislikes it and would prefer to keep it out of the language. But from a cursory search, I can't find any references for this claim. – huon May 25 '13 at 00:19