File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -492,3 +492,32 @@ If we forget to implement `Foo`, Rust will tell us:
492
492
``` text
493
493
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
494
494
```
495
+
496
+ # Deriving
497
+
498
+ Implementing traits like ` Debug ` and ` Default ` over and over again can become
499
+ quite tedious. For that reason, Rust provides an [ attribute] [ attributes ] that
500
+ allows you to let Rust automatically implement traits for you:
501
+
502
+ ``` rust
503
+ #[derive(Debug )]
504
+ struct Foo ;
505
+
506
+ fn main () {
507
+ println! (" {:?}" , Foo );
508
+ }
509
+ ```
510
+
511
+ [ attributes ] : attributes.html
512
+
513
+ However, deriving is limited to a certain set of traits:
514
+
515
+ - ` Clone `
516
+ - ` Copy `
517
+ - ` Debug `
518
+ - ` Default `
519
+ - ` Eq `
520
+ - ` Hash `
521
+ - ` Ord `
522
+ - ` PartialEq `
523
+ - ` PartialOrd `
You can’t perform that action at this time.
0 commit comments