summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDivay Prakash <divayprakash@users.noreply.github.com>2020-02-16 19:29:13 +0530
committerGitHub <noreply@github.com>2020-02-16 19:29:13 +0530
commit9641d773d14878d520e077eff8e7adb3b425ea6f (patch)
treedc5e32af07e5867f858febc2241d4664b8b1752e
parentae75b35f5f2e75396984f79c081746e6f408a072 (diff)
parent602dbf5267ff15ab137bee2dbedad7f500d039a2 (diff)
Merge pull request #3857 from polazarus/patch-1
[rust/en] Change misleading method and add two other methods
-rw-r--r--rust.html.markdown10
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) //