manual: mention overloading, traits on the arithmetic and bitwise operators.

This commit is contained in:
Graydon Hoare 2012-10-11 14:09:44 -07:00
parent edf493f07b
commit eff4a36b3e

View File

@ -1674,40 +1674,49 @@ Binary operators expressions are given in terms of
#### Arithmetic operators #### Arithmetic operators
Binary arithmetic expressions require both their operands to be of the Binary arithmetic expressions are syntactic sugar for calls to built-in traits,
same type, and can be applied only to numeric types, with the defined in the `core::ops` module of the `core` library.
exception of `+`, which acts both as addition operator on numbers and This means that arithmetic operators can be overridden for user-defined types.
as concatenate operator on vectors and strings. The default meaning of the operators on standard types is given here.
`+` `+`
: Addition and vector/string concatenation. : Addition and vector/string concatenation.
Calls the `add` method on the `core::ops::Add` trait.
`-` `-`
: Subtraction. : Subtraction.
Calls the `sub` method on the `core::ops::Sub` trait.
`*` `*`
: Multiplication. : Multiplication.
Calls the `mul` method on the `core::ops::Mul` trait.
`/` `/`
: Division. : 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
Bitwise operators apply only to integer types, and perform their Bitwise operators apply are, like the [arithmetic operators](#arithmetic-operators),
operation on the bits of the two's complement representation of the syntactic sugar for calls to built-in traits.
values. 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. : And.
Calls the `bitand` method on the `core::ops::BitAnd` trait.
`|` `|`
: Inclusive or. : Inclusive or.
Calls the `bitor` method on the `core::ops::BitOr` trait.
`^` `^`
: Exclusive or. : Exclusive or.
Calls the `bitxor` method on the `core::ops::BitXor` trait.
`<<` `<<`
: Logical left shift. : Logical left shift.
Calls the `shl` method on the `core::ops::Shl` trait.
`>>` `>>`
: Logical right shift. : Logical right shift.
`>>>` Calls the `shr` method on the `core::ops::Shr` trait.
: Arithmetic right shift.
#### Lazy boolean operators #### Lazy boolean operators