Skip to content

Commit 3d28927

Browse files
Improve Clone doc
1 parent 3344f89 commit 3d28927

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/libcore/clone.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
//! assign them or pass them as arguments, the receiver will get a copy,
1515
//! leaving the original value in place. These types do not require
1616
//! 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
1818
//! 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
2125
//!
2226
//! Basic usage example:
2327
//!
@@ -46,22 +50,22 @@
4650

4751
/// A common trait for the ability to explicitly duplicate an object.
4852
///
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
5054
/// `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
5256
/// may reimplement `Clone` and run arbitrary code.
5357
///
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.
5660
///
5761
/// ## Derivable
5862
///
5963
/// 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.
6165
///
6266
/// ## How can I implement `Clone`?
6367
///
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:
6569
/// if `T: Copy`, `x: T`, and `y: &T`, then `let x = y.clone();` is equivalent to `let x = *y;`.
6670
/// Manual implementations should be careful to uphold this invariant; however, unsafe code
6771
/// must not rely on it to ensure memory safety.
@@ -70,6 +74,9 @@
7074
/// library only implements `Clone` up until arrays of size 32. In this case, the implementation of
7175
/// `Clone` cannot be `derive`d, but can be implemented as:
7276
///
77+
/// [`Copy`]: ../../std/marker/trait.Copy.html
78+
/// [`clone()`]: trait.Clone.html#tymethod.clone
79+
///
7380
/// ```
7481
/// #[derive(Copy)]
7582
/// struct Stats {

0 commit comments

Comments
 (0)