summary refs log tree commit diff
path: root/src/doc/style/features/traits/README.md
blob: 1893db24466fa861a075035a917092a81b021094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
% Traits

Traits are probably Rust's most complex feature, supporting a wide range of use
cases and design tradeoffs. Patterns of trait usage are still emerging.

### Know whether a trait will be used as an object. [FIXME: needs RFC]

Trait objects have some [significant limitations](objects.md): methods
invoked through a trait object cannot use generics, and cannot use
`Self` except in receiver position.

When designing a trait, decide early on whether the trait will be used
as an [object](objects.md) or as a [bound on generics](generics.md);
the tradeoffs are discussed in each of the linked sections.

If a trait is meant to be used as an object, its methods should take
and return trait objects rather than use generics.


### Default methods [FIXME]

> **[FIXME]** Guidelines for default methods.