File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
branches/snap-stage3/src/libcore Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: a0f86de49748b472d4d189d9688b0d856c000914
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: 5eb254b1ccf196ea0856782eba96f92ae0786617
4
+ refs/heads/snap-stage3: 39676c8bf0ad0fe7249f788ab6ab6790360af73c
5
5
refs/heads/try: 08f6380a9f0b866796080094f44fe25ea5636547
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
Original file line number Diff line number Diff line change 13
13
//! Implementing these traits allows you to get an effect similar to
14
14
//! overloading operators.
15
15
//!
16
- //! The values for the right hand side of an operator are automatically
17
- //! borrowed, so `a + b` is sugar for `a.add(&b)`.
18
- //!
19
- //! All of these traits are imported by the prelude, so they are available in
16
+ //! Some of these traits are imported by the prelude, so they are available in
20
17
//! every Rust program.
21
18
//!
19
+ //! Many of the operators take their operands by value. In non-generic
20
+ //! contexts involving built-in types, this is usually not a problem.
21
+ //! However, using these operators in generic code, requires some
22
+ //! attention if values have to be reused as opposed to letting the operators
23
+ //! consume them. One option is to occasionally use `clone()`.
24
+ //! Another option is to rely on the types involved providing additional
25
+ //! operator implementations for references. For example, for a user-defined
26
+ //! type `T` which is supposed to support addition, it is probably a good
27
+ //! idea to have both `T` and `&T` implement the traits `Add<T>` and `Add<&T>`
28
+ //! so that generic code can be written without unnecessary cloning.
29
+ //!
22
30
//! # Example
23
31
//!
24
32
//! This example creates a `Point` struct that implements `Add` and `Sub`, and then
You can’t perform that action at this time.
0 commit comments