Skip to content

Commit 4d7eee1

Browse files
committed
trpl: mention deriving in traits section
1 parent e362679 commit 4d7eee1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/doc/trpl/traits.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,32 @@ If we forget to implement `Foo`, Rust will tell us:
492492
```text
493493
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
494494
```
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`

0 commit comments

Comments
 (0)