Skip to content
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

Explain why &self is common #23788

Merged
merged 1 commit into from
Mar 28, 2015
Merged

Explain why &self is common #23788

merged 1 commit into from
Mar 28, 2015

Conversation

steveklabnik
Copy link
Member

Fixes #23748

@rust-highfive
Copy link
Collaborator

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -51,7 +51,8 @@ You can think of this first parameter as being the `x` in `x.foo()`. The three
variants correspond to the three kinds of thing `x` could be: `self` if it's
just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
a mutable reference. We should default to using `&self`, as it's the most
common. Here's an example of all three variants:
common, as Rustaceans prefer borrowing over taking ownership, and immutable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "immutable borrowing" should be called "shared borrowing"?

@steveklabnik
Copy link
Member Author

@alexcrichton updated, what do you think of this?

@alexcrichton
Copy link
Member

@bors: r+ e604382 rollup

Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 28, 2015
bors added a commit that referenced this pull request Mar 28, 2015
@bors bors merged commit e604382 into rust-lang:master Mar 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

book: explain why we default to &self as first parameter in methods
6 participants