@@ -498,18 +498,25 @@ 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 with the exception that all
516
+ traits except the first trait must be auto traits and there may not be more than
517
+ one lifetime. For example, given a trait ` Trait ` , the following
518
+ are all trait objects: ` Trait ` , ` Trait + Send ` , ` Trait + Send + Sync ` ,
519
+ ` Trait + 'static ` , ` Trait + Send + 'static` , ` Trait + ` , ` 'static + Trait ` .
513
520
514
521
Two trait object types alias each other if the base traits alias each other and
515
522
if the sets of auto traits are the same and the lifetime bounds are the same.
@@ -701,3 +708,5 @@ impl Printable for String {
701
708
[ object safe ] : items/traits.html#object-safety
702
709
[ issue 47010 ] : https://github.com/rust-lang/rust/issues/47010
703
710
[ issue 33140 ] : https://github.com/rust-lang/rust/issues/33140
711
+ [ _PATH_ ] : paths.html
712
+ [ _LIFETIME_OR_LABEL_ ] : tokens.html#lifetimes-and-loop-labels
0 commit comments