From 4d7eee1817582c4bf70862d47aca9e75bb264bc7 Mon Sep 17 00:00:00 2001 From: panicbit Date: Thu, 8 Oct 2015 07:10:56 +0200 Subject: [PATCH 1/2] trpl: mention deriving in traits section --- src/doc/trpl/traits.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 0870a6ef34147..8726a29d710dc 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -492,3 +492,32 @@ If we forget to implement `Foo`, Rust will tell us: ```text error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277] ``` + +# Deriving + +Implementing traits like `Debug` and `Default` over and over again can become +quite tedious. For that reason, Rust provides an [attribute][attributes] that +allows you to let Rust automatically implement traits for you: + +```rust +#[derive(Debug)] +struct Foo; + +fn main() { + println!("{:?}", Foo); +} +``` + +[attributes]: attributes.html + +However, deriving is limited to a certain set of traits: + +- `Clone` +- `Copy` +- `Debug` +- `Default` +- `Eq` +- `Hash` +- `Ord` +- `PartialEq` +- `PartialOrd` From 7515514fdccbfb7e41b9ba7844f9b34308efe7f0 Mon Sep 17 00:00:00 2001 From: panicbit Date: Thu, 8 Oct 2015 07:27:26 +0200 Subject: [PATCH 2/2] trpl: link to derivable trait's docs --- src/doc/trpl/traits.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 8726a29d710dc..27debf86e396b 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -512,12 +512,12 @@ fn main() { However, deriving is limited to a certain set of traits: -- `Clone` -- `Copy` -- `Debug` -- `Default` -- `Eq` -- `Hash` -- `Ord` -- `PartialEq` -- `PartialOrd` +- [`Clone`](../core/clone/trait.Clone.html) +- [`Copy`](../core/marker/trait.Copy.html) +- [`Debug`](../core/fmt/trait.Debug.html) +- [`Default`](../core/default/trait.Default.html) +- [`Eq`](../core/cmp/trait.Eq.html) +- [`Hash`](../core/hash/trait.Hash.html) +- [`Ord`](../core/cmp/trait.Ord.html) +- [`PartialEq`](../core/cmp/trait.PartialEq.html) +- [`PartialOrd`](../core/cmp/trait.PartialOrd.html)