Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 605
Document Rc/Arc method receivers.#494
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -93,9 +93,37 @@ Associated functions whose first parameter is named `self` are called *methods* | ||
| and may be invoked using the [method call operator], for example, `x.foo()`, as | ||
| well as the usual function call notation. | ||
| If the type of the `self` parameter is specified, it is limited to the type | ||
| being implemented (or `Self`), or a reference or mutable reference to the | ||
| type, or a boxed value of the type being implemented (such as `Box<Self>`). | ||
| If the type of the `self` parameter is specified, it is limited to one of the | ||
| following types: | ||
| - `Self` | ||
| - `&Self` | ||
| - `&mut Self` | ||
| - [`Box<Self>`] | ||
| - [`Rc<Self>`] | ||
| - [`Arc<Self>`] | ||
| - [`Pin<P>`] where `P` is one of the above types except `Self`. | ||
| The `Self` term can be replaced with the type being implemented. | ||
| ```rust | ||
| # use std::rc::Rc; | ||
| # use std::sync::Arc; | ||
| # use std::pin::Pin; | ||
| struct Example; | ||
| impl Example { | ||
| fn by_value(self: Self) {} | ||
| fn by_ref(self: &Self) {} | ||
| fn by_ref_mut(self: &mut Self) {} | ||
Centril marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| fn by_box(self: Box<Self>) {} | ||
| fn by_rc(self: Rc<Self>) {} | ||
| fn by_arc(self: Arc<Self>) {} | ||
| fn by_pin(self: Pin<&Self>) {} | ||
| fn explicit_type(self: Arc<Example>) {} | ||
| fn with_lifetime<'a>(self: &'a Self) {} | ||
| } | ||
| ``` | ||
| Shorthand syntax can be used without specifying a type, which have the | ||
| following equivalents: | ||
| @@ -107,7 +135,17 @@ Shorthand | Equivalent | ||
| > Note: Lifetimes can be and usually are elided with this shorthand. | ||
| Consider the following trait: | ||
| If the `self` parameter is prefixed with `mut`, it becomes a mutable variable, | ||
| similar to regular parameters using a `mut` [identifier pattern]. For example: | ||
| ```rust | ||
| trait Changer: Sized { | ||
| fn change(mut self) {} | ||
| fn modify(mut self: Box<Self>) {} | ||
| } | ||
| ``` | ||
| As an example of methods on a trait, consider the following: | ||
| ```rust | ||
| # type Surface = i32; | ||
| @@ -294,11 +332,16 @@ fn main() { | ||
| [_Lifetime_]: trait-bounds.html | ||
| [_Type_]: types.html#type-expressions | ||
| [_WhereClause_]: items/generics.html#where-clauses | ||
| [`Arc<Self>`]: special-types-and-traits.html#arct | ||
| [`Box<Self>`]: special-types-and-traits.html#boxt | ||
| [`Pin<P>`]: special-types-and-traits.html#pinp | ||
| [`Rc<Self>`]: special-types-and-traits.html#rct | ||
| [trait]: items/traits.html | ||
| [traits]: items/traits.html | ||
| [type aliases]: items/type-aliases.html | ||
| [inherent implementations]: items/implementations.html#inherent-implementations | ||
| [identifier]: identifiers.html | ||
| [identifier pattern]: patterns.html#identifier-patterns | ||
| [trait object]: types/trait-object.html | ||
| [implementations]: items/implementations.html | ||
| [type]: types.html#type-expressions | ||
This file contains hidden or 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
This file contains hidden or 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
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.
This seems a little awkward, but I expect it to be temporary until the more general rules are stabilized. I think it could alternatively be written "one of the above types that can Deref to Self".