@@ -14,14 +14,19 @@ other traits and so forth as usual.
14
14
15
15
Traits are implemented for specific types through separate [ implementations] .
16
16
17
+ Items associated with a trait do not need to be defined in the trait, but they
18
+ may be. If the trait provides a definition, then this definition acts as a
19
+ default for any implementation which does not override it. If it does not, then
20
+ any implementation must provide a definition.
21
+
17
22
## Trait bounds
18
23
19
24
Generic functions may use traits as _ bounds_ on their type parameters. This
20
25
will have three effects:
21
26
22
27
- Only types that have the trait may instantiate the parameter.
23
- - Within the generic function, the methods of the trait can be called on values
24
- that have the parameter's type. Associated types can be used in the
28
+ - Within the generic function, the functions of the trait can be called on
29
+ values that have the parameter's type. Associated types can be used in the
25
30
function's signature, and associated constants can be used in expressions
26
31
within the function body.
27
32
- Generic functions and types with the same or weaker bounds can use the
@@ -63,11 +68,10 @@ Object safe traits can be the base trait of a [trait object]. A trait is
63
68
* object safe* if it has the following qualities (defined in [ RFC 255] ):
64
69
65
70
* It must not require ` Self: Sized `
66
- * All associated functions must either have a ` where Self: Sized ` bound or
67
- * Not have any type parameters (although lifetime parameters are allowed)
68
- * Must be a method: its first parameter must be called self, with type
69
- ` Self ` , ` &Self ` , ` &mut Self ` , ` Box<Self> ` .
70
- * ` Self ` may only be used in the type of the receiver.
71
+ * All associated functions must either have a ` where Self: Sized ` bound, or
72
+ * Not have any type parameters (although lifetime parameters are allowed),
73
+ and
74
+ * Be a [ method] that does not use ` Self ` except in the type of the receiver.
71
75
* It must not have any associated constants.
72
76
73
77
## Supertraits
@@ -142,6 +146,6 @@ let nonsense = mycircle.radius() * mycircle.area();
142
146
[ `RefUnwindSafe` ] : ../std/panic/trait.RefUnwindSafe.html
143
147
[ trait object ] : types.html#trait-objects
144
148
[ explicit ] : expressions/operator-expr.html#type-cast-expressions
145
- [ methods called ] : expressions/method-call-expr.html
146
149
[ RFC 255 ] : https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
147
- [ associated items ] : items/associated-items.html
150
+ [ associated items ] : items/associated-items.html
151
+ [ method ] : items/functions.html#methods
0 commit comments