@@ -14,15 +14,14 @@ number of [auto traits].
14
14
Trait objects implement the base trait, its auto traits, and any [ supertraits]
15
15
of the base trait.
16
16
17
- Trait objects are written as the optional keyword ` dyn ` followed by a set of
18
- trait bounds, but with the following restrictions on the trait bounds. All
19
- traits except the first trait must be auto traits, there may not be more than
20
- one lifetime, and opt-out bounds (e.g. ` ?Sized ` ) are not allowed. Furthermore,
17
+ Trait objects are written as the keyword ` dyn ` followed by a set of trait
18
+ bounds, but with the following restrictions on the trait bounds. All traits
19
+ except the first trait must be auto traits, there may not be more than one
20
+ lifetime, and opt-out bounds (e.g. ` ?Sized ` ) are not allowed. Furthermore,
21
21
paths to traits may be parenthesized.
22
22
23
23
For example, given a trait ` Trait ` , the following are all trait objects:
24
24
25
- * ` Trait `
26
25
* ` dyn Trait `
27
26
* ` dyn Trait + Send `
28
27
* ` dyn Trait + Send + Sync `
@@ -32,6 +31,12 @@ For example, given a trait `Trait`, the following are all trait objects:
32
31
* ` dyn 'static + Trait ` .
33
32
* ` dyn (Trait) `
34
33
34
+ > ** Edition Differences** : Before the 2021 edition, the ` dyn ` keyword may be
35
+ > omitted.
36
+ >
37
+ > Note: For clarity, it is recommended to always use the ` dyn ` keyword on your
38
+ > trait objects unless your codebase supports compiling with Rust 1.26 or lower.
39
+
35
40
> ** Edition Differences** : In the 2015 edition, if the first bound of the
36
41
> trait object is a path that starts with ` :: ` , then the ` dyn ` will be treated
37
42
> as a part of the path. The first path can be put in parenthesis to get
@@ -41,9 +46,6 @@ For example, given a trait `Trait`, the following are all trait objects:
41
46
> Beginning in the 2018 edition, ` dyn ` is a true keyword and is not allowed in
42
47
> paths, so the parentheses are not necessary.
43
48
44
- > Note: For clarity, it is recommended to always use the ` dyn ` keyword on your
45
- > trait objects unless your codebase supports compiling with Rust 1.26 or lower.
46
-
47
49
Two trait object types alias each other if the base traits alias each other and
48
50
if the sets of auto traits are the same and the lifetime bounds are the same.
49
51
For example, ` dyn Trait + Send + UnwindSafe ` is the same as
0 commit comments