mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-03 15:40:17 +00:00
rust/Types: Add reminder for different forms of 'self' parameter
This commit is contained in:
parent
25f882d1db
commit
b8600d8082
@ -43,7 +43,10 @@
|
||||
// Methods //
|
||||
|
||||
impl<T> Foo<T> {
|
||||
// Methods take an explicit `self` parameter
|
||||
// Instance methods take an explicit `self` parameter.
|
||||
// Using `self` on its own will consume the caller, while
|
||||
// `&self` or `&mut self` will create immutable and mutable
|
||||
// references, respectively.
|
||||
fn get_bar(self) -> T {
|
||||
self.bar
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user