|
14 | 14 | //! assign them or pass them as arguments, the receiver will get a copy,
|
15 | 15 | //! leaving the original value in place. These types do not require
|
16 | 16 | //! allocation to copy and do not have finalizers (i.e. they do not
|
17 |
| -//! contain owned boxes or implement `Drop`), so the compiler considers |
| 17 | +//! contain owned boxes or implement [`Drop`]), so the compiler considers |
18 | 18 | //! them cheap and safe to copy. For other types copies must be made
|
19 |
| -//! explicitly, by convention implementing the `Clone` trait and calling |
20 |
| -//! the `clone` method. |
| 19 | +//! explicitly, by convention implementing the [`Clone`] trait and calling |
| 20 | +//! the [`clone`][clone] method. |
| 21 | +//! |
| 22 | +//! [`Clone`]: trait.Clone.html |
| 23 | +//! [clone]: trait.Clone.html#tymethod.clone |
| 24 | +//! [`Drop`]: ../../std/ops/trait.Drop.html |
21 | 25 | //!
|
22 | 26 | //! Basic usage example:
|
23 | 27 | //!
|
|
46 | 50 |
|
47 | 51 | /// A common trait for the ability to explicitly duplicate an object.
|
48 | 52 | ///
|
49 |
| -/// Differs from `Copy` in that `Copy` is implicit and extremely inexpensive, while |
| 53 | +/// Differs from [`Copy`] in that [`Copy`] is implicit and extremely inexpensive, while |
50 | 54 | /// `Clone` is always explicit and may or may not be expensive. In order to enforce
|
51 |
| -/// these characteristics, Rust does not allow you to reimplement `Copy`, but you |
| 55 | +/// these characteristics, Rust does not allow you to reimplement [`Copy`], but you |
52 | 56 | /// may reimplement `Clone` and run arbitrary code.
|
53 | 57 | ///
|
54 |
| -/// Since `Clone` is more general than `Copy`, you can automatically make anything |
55 |
| -/// `Copy` be `Clone` as well. |
| 58 | +/// Since `Clone` is more general than [`Copy`], you can automatically make anything |
| 59 | +/// [`Copy`] be `Clone` as well. |
56 | 60 | ///
|
57 | 61 | /// ## Derivable
|
58 | 62 | ///
|
59 | 63 | /// This trait can be used with `#[derive]` if all fields are `Clone`. The `derive`d
|
60 |
| -/// implementation of `clone()` calls `clone()` on each field. |
| 64 | +/// implementation of [`clone()`] calls [`clone()`] on each field. |
61 | 65 | ///
|
62 | 66 | /// ## How can I implement `Clone`?
|
63 | 67 | ///
|
64 |
| -/// Types that are `Copy` should have a trivial implementation of `Clone`. More formally: |
| 68 | +/// Types that are [`Copy`] should have a trivial implementation of `Clone`. More formally: |
65 | 69 | /// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`.
|
66 | 70 | /// Manual implementations should be careful to uphold this invariant; however, unsafe code
|
67 | 71 | /// must not rely on it to ensure memory safety.
|
|
70 | 74 | /// library only implements `Clone` up until arrays of size 32. In this case, the implementation of
|
71 | 75 | /// `Clone` cannot be `derive`d, but can be implemented as:
|
72 | 76 | ///
|
| 77 | +/// [`Copy`]: ../../std/marker/trait.Copy.html |
| 78 | +/// [`clone()`]: trait.Clone.html#tymethod.clone |
| 79 | +/// |
73 | 80 | /// ```
|
74 | 81 | /// #[derive(Copy)]
|
75 | 82 | /// struct Stats {
|
|
0 commit comments