【发布时间】:2022-11-27 02:32:35
【问题描述】:
我怎样才能调用一个接收我的结构作为参数并将该闭包作为成员的闭包?
type Thunk = Box<dyn FnMut(&mut Config) + Send + 'static>;
struct Config {
s: String,
f: Thunk,
}
impl Config {
fn run(&mut self) {
// the problem is here
(self.f)(self);
}
}
fn main() {
let cfg = Config {s: String::from("hello"), f: Box::new( |c| {
println!("{}", c.s);
}) };
}
提前致谢
【问题讨论】: