diff options
author | Divay Prakash <divayprakash@users.noreply.github.com> | 2020-02-16 19:29:13 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-16 19:29:13 +0530 |
commit | 9641d773d14878d520e077eff8e7adb3b425ea6f (patch) | |
tree | dc5e32af07e5867f858febc2241d4664b8b1752e | |
parent | ae75b35f5f2e75396984f79c081746e6f408a072 (diff) | |
parent | 602dbf5267ff15ab137bee2dbedad7f500d039a2 (diff) |
Merge pull request #3857 from polazarus/patch-1
[rust/en] Change misleading method and add two other methods
-rw-r--r-- | rust.html.markdown | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rust.html.markdown b/rust.html.markdown index 413939bf..e835de12 100644 --- a/rust.html.markdown +++ b/rust.html.markdown @@ -176,13 +176,19 @@ 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 } } let a_foo = Foo { bar: 1 }; - println!("{}", a_foo.get_bar()); // 1 + println!("{}", a_foo.bar()); // 1 // Traits (known as interfaces or typeclasses in other languages) // |