See the code:
struct A {}
impl A {
fn a(&self) {}
}
pub fn main() {
let a = A {};
a.a();
A::a(&a);
}
Why a.a()
doesn't need the &
while A::a(&a)
needs? What's the difference?
See the code:
struct A {}
impl A {
fn a(&self) {}
}
pub fn main() {
let a = A {};
a.a();
A::a(&a);
}
Why a.a()
doesn't need the &
while A::a(&a)
needs? What's the difference?
In Rust, a.a()
is syntax sugar for A::a(&a)
, so a
does get borrowed in both calls. The dot operator does a lot more as well, you can read about that here.