With fully-qualified syntax, Foo::bar
will work, yielding a fn(&Foo) -> ()
(similar to Python).
let callback = Foo::bar;
// called like
callback(&foo);
However, if you want it with the self
variable already bound (as in, calling callback()
will be the same as calling bar
on the foo
object), then you need to use an explicit closure:
let callback = || foo.bar();
// called like
callback();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…