Skip to content

Commit de72cd3

Browse files
authored
Elaborate on deriving vs implementing Copy
1 parent c313c07 commit de72cd3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: core/src/marker.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,18 @@ marker_impls! {
288288
/// }
289289
/// ```
290290
///
291-
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
292-
/// bound on type parameters, which isn't always desired.
291+
/// There is a small difference between the two. The `derive` strategy will also place a `Copy`
292+
/// bound on type parameters:
293+
///
294+
/// ```
295+
/// struct MyStruct<T>;
296+
///
297+
/// impl<T: Copy> Copy for MyStruct<T> { }
298+
/// ```
299+
///
300+
/// This isn't always desired. For example, shared references (`&T`) can be copied regardless of
301+
/// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`]
302+
/// could potentially be duplicated with a bit-wise copy.
293303
///
294304
/// ## What's the difference between `Copy` and `Clone`?
295305
///

0 commit comments

Comments
 (0)