-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trait object syntax + trailing plus #255
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -498,18 +498,25 @@ Because captures are often by reference, the following general rules arise: | |
|
||
## Trait objects | ||
|
||
> **<sup>Syntax</sup>** | ||
> _TraitObjectType_ : | ||
> [_LifetimeOrPath_] ( `+` [_LifetimeOrPath_] )<sup>\*</sup> `+`<sup>?</sup> | ||
> | ||
> _LifetimeOrPath_ : | ||
> [_Path_] | [_LIFETIME_OR_LABEL_] | ||
|
||
A *trait object* is an opaque value of another type that implements a set of | ||
traits. The set of traits is made up of an [object safe] *base trait* plus any | ||
number of [auto traits]. | ||
|
||
Trait objects implement the base trait, its auto traits, and any super traits | ||
of the base trait. | ||
|
||
Trait objects are written as the path to the base trait followed by the list | ||
of auto traits followed optionally by a lifetime bound all separated by `+`. For | ||
example, given a trait `Trait`, the following are all trait objects: `Trait`, | ||
`Trait + Send`, `Trait + Send + Sync`, `Trait + 'static`, | ||
`Trait + Send + 'static`. | ||
Trait objects are written the same as trait bounds with the exception that all | ||
traits except the first trait must be auto traits and there may not be more than | ||
one lifetime. For example, given a trait `Trait`, the following | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
are all trait objects: `Trait`, `Trait + Send`, `Trait + Send + Sync`, | ||
`Trait + 'static`, `Trait + Send + 'static`, `Trait +`, `'static + Trait`. | ||
|
||
Two trait object types alias each other if the base traits alias each other and | ||
if the sets of auto traits are the same and the lifetime bounds are the same. | ||
|
@@ -701,3 +708,5 @@ impl Printable for String { | |
[object safe]: items/traits.html#object-safety | ||
[issue 47010]: https://github.com/rust-lang/rust/issues/47010 | ||
[issue 33140]: https://github.com/rust-lang/rust/issues/33140 | ||
[_PATH_]: paths.html | ||
[_LIFETIME_OR_LABEL_]: tokens.html#lifetimes-and-loop-labels |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be clearer as separate sentences instead of "with the exception that".