Skip to content

Commit 8600610

Browse files
committed
Rollup merge of #28904 - panicbit:trpl-derive, r=steveklabnik
2 parents ac541d3 + 7515514 commit 8600610

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`](../core/clone/trait.Clone.html)
516+
- [`Copy`](../core/marker/trait.Copy.html)
517+
- [`Debug`](../core/fmt/trait.Debug.html)
518+
- [`Default`](../core/default/trait.Default.html)
519+
- [`Eq`](../core/cmp/trait.Eq.html)
520+
- [`Hash`](../core/hash/trait.Hash.html)
521+
- [`Ord`](../core/cmp/trait.Ord.html)
522+
- [`PartialEq`](../core/cmp/trait.PartialEq.html)
523+
- [`PartialOrd`](../core/cmp/trait.PartialOrd.html)

0 commit comments

Comments
 (0)