Skip to content

Commit

Permalink
Elaborate on deriving vs implementing Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode authored Sep 3, 2024
1 parent c313c07 commit de72cd3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,18 @@ marker_impls! {
/// }
/// ```
///
/// There is a small difference between the two: the `derive` strategy will also place a `Copy`
/// bound on type parameters, which isn't always desired.
/// There is a small difference between the two. The `derive` strategy will also place a `Copy`
/// bound on type parameters:
///
/// ```
/// struct MyStruct<T>;
///
/// impl<T: Copy> Copy for MyStruct<T> { }
/// ```
///
/// This isn't always desired. For example, shared references (`&T`) can be copied regardless of
/// whether `T` is `Copy`. Likewise, a generic struct containing markers such as [`PhantomData`]
/// could potentially be duplicated with a bit-wise copy.
///
/// ## What's the difference between `Copy` and `Clone`?
///
Expand Down

0 comments on commit de72cd3

Please sign in to comment.