3 The *`derive` attribute* allows new [items] to be automatically generated for
4 data structures. It uses the [_MetaListPaths_] syntax to specify a list of
5 traits to implement or paths to [derive macros] to process.
7 For example, the following will create an [`impl` item] for the
8 [`PartialEq`] and [`Clone`] traits for `Foo`, and the type parameter `T` will be
9 given the `PartialEq` or `Clone` constraints for the appropriate `impl`:
12 #[derive(PartialEq, Clone)]
19 The generated `impl` for `PartialEq` is equivalent to
22 # struct Foo<T> { a: i32, b: T }
23 impl<T: PartialEq> PartialEq for Foo<T> {
24 fn eq(&self, other: &Foo<T>) -> bool {
25 self.a == other.a && self.b == other.b
30 You can implement `derive` for your own traits through [procedural macros].
32 ## The `automatically_derived` attribute
34 The *`automatically_derived` attribute* is automatically added to
35 [implementations] created by the `derive` attribute for built-in traits. It
36 has no direct effect, but it may be used by tools and diagnostic lints to
37 detect these automatically generated implementations.
39 [_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
40 [`Clone`]: ../../std/clone/trait.Clone.html
41 [`PartialEq`]: ../../std/cmp/trait.PartialEq.html
42 [`impl` item]: ../items/implementations.md
44 [derive macros]: ../procedural-macros.md#derive-macros
45 [implementations]: ../items/implementations.md
47 [procedural macros]: ../procedural-macros.md#derive-macros