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

rust-guide::20 method syntax - Suggestion to explain method chaining and types of self #16969

Closed
anmej opened this issue Sep 3, 2014 · 0 comments · Fixed by #21108
Closed

Comments

@anmej
Copy link

anmej commented Sep 3, 2014

cc @steveklabnik

In chapter 20 of the guide you write that x.foo().bar().baz() has better readability than baz(bar(foo(x))). However, afterwards you only give an example of a simple fn area(&self) -> f64 method.

I suggest adding an example of a method that allows chaining. Something like fn foo(&mut self) -> &mut T {...}, where T is the type of the struct.

In addition, it would be nice to explain the distinction between methods that take 'self', 'mut self', '&self' and '&mut self'. All of those can be used to implement method chaining, but with different purposes - some can be used to mutate the original value, while others can't, etc...

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 23, 2015
lnicola pushed a commit to lnicola/rust that referenced this issue Apr 20, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Apr 20, 2024
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 a pull request may close this issue.

2 participants