Skip to content

Commit 5112075

Browse files
committed
---
yaml --- r: 174701 b: refs/heads/snap-stage3 c: 39676c8 h: refs/heads/master i: 174699: 943844e v: v3
1 parent e7f9e9e commit 5112075

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: a0f86de49748b472d4d189d9688b0d856c000914
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5eb254b1ccf196ea0856782eba96f92ae0786617
4+
refs/heads/snap-stage3: 39676c8bf0ad0fe7249f788ab6ab6790360af73c
55
refs/heads/try: 08f6380a9f0b866796080094f44fe25ea5636547
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcore/ops.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@
1313
//! Implementing these traits allows you to get an effect similar to
1414
//! overloading operators.
1515
//!
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
2017
//! every Rust program.
2118
//!
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+
//!
2230
//! # Example
2331
//!
2432
//! This example creates a `Point` struct that implements `Add` and `Sub`, and then

0 commit comments

Comments
 (0)