File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,28 @@ fn main() {
2626
2727<details >
2828
29- Derivation is implemented with macros, and many crates provide useful derive
30- macros to add useful functionality. For example, ` serde ` can derive
31- serialization support for a struct using ` #[derive(Serialize)] ` .
29+ - Derivation is implemented with macros, and many crates provide useful derive
30+ macros to add useful functionality. For example, ` serde ` can derive
31+ serialization support for a struct using ` #[derive(Serialize)] ` .
32+
33+ - Derivation is usually provided for traits that have a common boilerplate-y
34+ implementation that is correct for most cases. For example, demonstrate how a
35+ manual ` Clone ` impl can be repetitive compared to deriving the trait:
36+
37+ ``` rust,skip
38+ impl Clone for Player {
39+ fn clone(&self) -> Self {
40+ Player {
41+ name: self.name.clone(),
42+ strength: self.strength.clone(),
43+ hit_points: self.hit_points.clone(),
44+ }
45+ }
46+ }
47+ ```
48+
49+ Not all of the ` .clone() ` s in the above are necessary in this case, but this
50+ demonstrates the generaly boilerplate-y pattern that manual impls would
51+ follow, which should help make the use of ` derive ` clear to students.
3252
3353</details >
You can’t perform that action at this time.
0 commit comments