Skip to content

Commit eff4a36

Browse files
committed
manual: mention overloading, traits on the arithmetic and bitwise operators.
1 parent edf493f commit eff4a36

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

doc/rust.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,40 +1674,49 @@ Binary operators expressions are given in terms of
16741674

16751675
#### Arithmetic operators
16761676

1677-
Binary arithmetic expressions require both their operands to be of the
1678-
same type, and can be applied only to numeric types, with the
1679-
exception of `+`, which acts both as addition operator on numbers and
1680-
as concatenate operator on vectors and strings.
1677+
Binary arithmetic expressions are syntactic sugar for calls to built-in traits,
1678+
defined in the `core::ops` module of the `core` library.
1679+
This means that arithmetic operators can be overridden for user-defined types.
1680+
The default meaning of the operators on standard types is given here.
16811681

16821682
`+`
16831683
: Addition and vector/string concatenation.
1684+
Calls the `add` method on the `core::ops::Add` trait.
16841685
`-`
16851686
: Subtraction.
1687+
Calls the `sub` method on the `core::ops::Sub` trait.
16861688
`*`
16871689
: Multiplication.
1690+
Calls the `mul` method on the `core::ops::Mul` trait.
16881691
`/`
16891692
: Division.
1693+
Calls the `div` method on the `core::ops::Div` trait.
16901694
`%`
1691-
: Remainder.
1695+
: Modulo (a.k.a. "remainder").
1696+
Calls the `modulo` method on the `core::ops::Modulo` trait.
16921697

16931698
#### Bitwise operators
16941699

1695-
Bitwise operators apply only to integer types, and perform their
1696-
operation on the bits of the two's complement representation of the
1697-
values.
1700+
Bitwise operators apply are, like the [arithmetic operators](#arithmetic-operators),
1701+
syntactic sugar for calls to built-in traits.
1702+
This means that bitwise operators can be overridden for user-defined types.
1703+
The default meaning of the operators on standard types is given here.
16981704

16991705
`&`
17001706
: And.
1707+
Calls the `bitand` method on the `core::ops::BitAnd` trait.
17011708
`|`
17021709
: Inclusive or.
1710+
Calls the `bitor` method on the `core::ops::BitOr` trait.
17031711
`^`
17041712
: Exclusive or.
1713+
Calls the `bitxor` method on the `core::ops::BitXor` trait.
17051714
`<<`
17061715
: Logical left shift.
1716+
Calls the `shl` method on the `core::ops::Shl` trait.
17071717
`>>`
17081718
: Logical right shift.
1709-
`>>>`
1710-
: Arithmetic right shift.
1719+
Calls the `shr` method on the `core::ops::Shr` trait.
17111720

17121721
#### Lazy boolean operators
17131722

0 commit comments

Comments
 (0)