17

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
MFlamer
  • 2,340
  • 2
  • 18
  • 25

1 Answers1

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
kmdreko
  • 42,554
  • 6
  • 57
  • 106
huon
  • 94,605
  • 21
  • 231
  • 225
  • 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