@@ -498,18 +498,26 @@ Because captures are often by reference, the following general rules arise:
498
498
499
499
## Trait objects
500
500
501
+ > ** <sup >Syntax</sup >**
502
+ > _ TraitObjectType_ :
503
+ >   ;  ; _ LifetimeOrPath_ ( ` + ` _ LifetimeOrPath_ )<sup >\* </sup > ` + ` <sup >?</sup >
504
+ >
505
+ > _ LifetimeOrPath_ :
506
+ >   ;  ; [ _ Path_ ] | [ _ LIFETIME_OR_LABEL_ ]
507
+
501
508
A * trait object* is an opaque value of another type that implements a set of
502
509
traits. The set of traits is made up of an [ object safe] * base trait* plus any
503
510
number of [ auto traits] .
504
511
505
512
Trait objects implement the base trait, its auto traits, and any super traits
506
513
of the base trait.
507
514
508
- Trait objects are written as the path to the base trait followed by the list
509
- of auto traits followed optionally by a lifetime bound all separated by ` + ` . For
510
- example, given a trait ` Trait ` , the following are all trait objects: ` Trait ` ,
511
- ` Trait + Send ` , ` Trait + Send + Sync ` , ` Trait + 'static ` ,
512
- ` Trait + Send + 'static ` .
515
+ Trait objects are written the same as trait bounds, but with the following
516
+ restrictions. All traits except the first trait must be auto traits, there may
517
+ not be more than one lifetime, and opt-out bounds (e.g. ` ?sized ` ) are not
518
+ allowed. For example, given a trait ` Trait ` , the following are all trait
519
+ objects: ` Trait ` , ` Trait + Send ` , ` Trait + Send + Sync ` , ` Trait + 'static ` ,
520
+ ` Trait + Send + 'static ` , ` Trait + ` , ` 'static + Trait ` .
513
521
514
522
Two trait object types alias each other if the base traits alias each other and
515
523
if the sets of auto traits are the same and the lifetime bounds are the same.
@@ -644,3 +652,5 @@ impl Printable for String {
644
652
[ object safe ] : items/traits.html#object-safety
645
653
[ issue 47010 ] : https://github.com/rust-lang/rust/issues/47010
646
654
[ issue 33140 ] : https://github.com/rust-lang/rust/issues/33140
655
+ [ _PATH_ ] : paths.html
656
+ [ _LIFETIME_OR_LABEL_ ] : tokens.html#lifetimes-and-loop-labels
0 commit comments