about summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-10-11 14:09:44 -0700
committerGraydon Hoare <graydon@mozilla.com>2012-10-11 14:18:52 -0700
commiteff4a36b3e5cfbd2b08bb5a3e8d07396dc532033 (patch)
tree6624d35666503e3bc067b22f2881af1ef10b860c /doc
parentedf493f07b5316363a3ced23572c7ed79310b048 (diff)
downloadrust-eff4a36b3e5cfbd2b08bb5a3e8d07396dc532033.tar.gz
rust-eff4a36b3e5cfbd2b08bb5a3e8d07396dc532033.zip
manual: mention overloading, traits on the arithmetic and bitwise operators.
Diffstat (limited to 'doc')
-rw-r--r--doc/rust.md29
1 files changed, 19 insertions, 10 deletions
diff --git a/doc/rust.md b/doc/rust.md
index 66e143734b5..fb5337baf2e 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -1674,40 +1674,49 @@ Binary operators expressions are given in terms of
 
 #### Arithmetic operators
 
-Binary arithmetic expressions require both their operands to be of the
-same type, and can be applied only to numeric types, with the
-exception of `+`, which acts both as addition operator on numbers and
-as concatenate operator on vectors and strings.
+Binary arithmetic expressions are syntactic sugar for calls to built-in traits,
+defined in the `core::ops` module of the `core` library.
+This means that arithmetic operators can be overridden for user-defined types.
+The default meaning of the operators on standard types is given here.
 
 `+`
   : Addition and vector/string concatenation.
+    Calls the `add` method on the `core::ops::Add` trait.
 `-`
   : Subtraction.
+    Calls the `sub` method on the `core::ops::Sub` trait.
 `*`
   : Multiplication.
+    Calls the `mul` method on the `core::ops::Mul` trait.
 `/`
   : Division.
+    Calls the `div` method on the `core::ops::Div` trait.
 `%`
-  : Remainder.
+  : Modulo (a.k.a. "remainder").
+    Calls the `modulo` method on the `core::ops::Modulo` trait.
 
 #### Bitwise operators
 
-Bitwise operators apply only to integer types, and perform their
-operation on the bits of the two's complement representation of the
-values.
+Bitwise operators apply are, like the [arithmetic operators](#arithmetic-operators),
+syntactic sugar for calls to built-in traits.
+This means that bitwise operators can be overridden for user-defined types.
+The default meaning of the operators on standard types is given here.
 
 `&`
   : And.
+    Calls the `bitand` method on the `core::ops::BitAnd` trait.
 `|`
   : Inclusive or.
+    Calls the `bitor` method on the `core::ops::BitOr` trait.
 `^`
   : Exclusive or.
+    Calls the `bitxor` method on the `core::ops::BitXor` trait.
 `<<`
   : Logical left shift.
+    Calls the `shl` method on the `core::ops::Shl` trait.
 `>>`
   : Logical right shift.
-`>>>`
-  : Arithmetic right shift.
+    Calls the `shr` method on the `core::ops::Shr` trait.
 
 #### Lazy boolean operators