diff options
author | polazarus <polazarus@users.noreply.github.com> | 2020-02-12 21:18:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-12 21:18:41 +0100 |
commit | 33921c9e6c30e07bbc1a6187ac364429a84d04bf (patch) | |
tree | bee2f9373aa68883c110034877a5859625ee41b4 /rust.html.markdown | |
parent | 76db052c9e3324295a94d67b26da50681307db0a (diff) |
[Rust] Change misleading method and add two other methods
The `get_bar` method consumes `self`. The name is misleading and does not respect the language naming convention.
This PR renames it to `into_bar` and provides `bar` (a getter) and `bar_mut` (to get a mutable reference).
Diffstat (limited to 'rust.html.markdown')
-rw-r--r-- | rust.html.markdown | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/rust.html.markdown b/rust.html.markdown index 413939bf..83682c01 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -176,7 +176,13 @@ fn main() { impl<T> Foo<T> { // Methods take an explicit `self` parameter - fn get_bar(self) -> T { + fn bar(&self) -> &T { // self is borrowed + &self.bar + } + fn bar_mut(&mut self) -> &mut T { // self is mutably borrowed + &mut self.bar + } + fn into_bar(self) -> T { // here self is consumed self.bar } } |