Skip to content

Commit 494d490

Browse files
committed
Trait object syntax + trailing plus
1 parent ec079d3 commit 494d490

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/types.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,18 +498,25 @@ Because captures are often by reference, the following general rules arise:
498498

499499
## Trait objects
500500

501+
> **<sup>Syntax</sup>**
502+
> _TraitObjectType_ :
503+
> &nbsp;&nbsp; [_LifetimeOrPath_] ( `+` [_LifetimeOrPath_] )<sup>\*</sup> `+`<sup>?</sup>
504+
>
505+
> _LifetimeOrPath_ :
506+
> &nbsp;&nbsp; [_Path_] | [_LIFETIME_OR_LABEL_]
507+
501508
A *trait object* is an opaque value of another type that implements a set of
502509
traits. The set of traits is made up of an [object safe] *base trait* plus any
503510
number of [auto traits].
504511

505512
Trait objects implement the base trait, its auto traits, and any super traits
506513
of the base trait.
507514

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`.
513520

514521
Two trait object types alias each other if the base traits alias each other and
515522
if the sets of auto traits are the same and the lifetime bounds are the same.
@@ -701,3 +708,5 @@ impl Printable for String {
701708
[object safe]: items/traits.html#object-safety
702709
[issue 47010]: https://github.com/rust-lang/rust/issues/47010
703710
[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

Comments
 (0)