我有一个函数init
,其参数中包含一个configure
lambda:
fn init<T>(configure: T)
where
T: Fn<Rc<RefCell<SomeStruct>>>,
{
let mut some_struct: SomeStruct = /*...*/;
configure(&mut some_struct); // what to do here?
}
如何创建这样的东西?
答案 0 :(得分:2)
目前尚不清楚您的确切问题是什么,但我想您应该 尝试了最明显的方法:
#[derive(Default)]
struct SomeStruct;
fn init<T>(configure: T)
where
T: Fn(&mut SomeStruct),
{
let mut some_struct = SomeStruct::default();
configure(&mut some_struct);
}