diff options
| author | panicbit <panicbit.dev@gmail.com> | 2015-10-08 07:10:56 +0200 |
|---|---|---|
| committer | panicbit <panicbit.dev@gmail.com> | 2015-10-08 07:15:39 +0200 |
| commit | 4d7eee1817582c4bf70862d47aca9e75bb264bc7 (patch) | |
| tree | 94ebc5aae7224dfbe5a079bea4d99b9162627dbd /src | |
| parent | e362679bb6a76064442492fdd5e07f06854f5605 (diff) | |
| download | rust-4d7eee1817582c4bf70862d47aca9e75bb264bc7.tar.gz rust-4d7eee1817582c4bf70862d47aca9e75bb264bc7.zip | |
trpl: mention deriving in traits section
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/trpl/traits.md | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 0870a6ef341..8726a29d710 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` |
