3 ms·
No, you can't do it when you need &self.
by EugeneOZ 11y ago
No, you can't do it when you need &self.
- kzrdude 11y agoYou have me guessing you want a bound method where self is implicitly supplied. Sure, there's no sugar for that.
- dbaupp 11y agoYou can, e.g. struct Foo; impl Foo { fn bar(&self) {} } fn main() { let x = Foo; Foo::bar(&x); } What you may be encountering is you can't pass a `Foo` when a `&Foo` is expected (why I needed to write &x), because the types differ. Calls with method syntax don't see this because they automatically borrow the receiver if necessary, but explicit function calls do not do this sort of borrowing and so the types need to line up right.