【发布时间】:2018-01-15 07:26:34
【问题描述】:
我正在编写如下代码:
use std::cell::RefCell;
struct CallbackWithArgs<T> {
callback: Box<Fn(&mut T) -> ()>,
arg: RefCell<T>,
}
struct S {
args: CallbackWithArgs<_>,
}
编译器出错:
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> src/main.rs:9:28
|
9 | args: CallbackWithArgs<_>,
| ^ not allowed in type signatures
这样做的正确方法是什么?
【问题讨论】:
-
请同时添加编译错误。
-
"那么有人能告诉我正确的方法吗?"这是什么”?你想做什么?
-
你为什么不让
S泛型来允许任何类型? -
编译器错误类似于
expectstd::any::Any + 'static, foundstd::any::Any``。因此,在我正确设置生命周期后,此错误已得到修复。我认为问题已经消失了。但是,对于泛型类型声明中生命周期和特征声明的组合,我仍然有些困惑。
标签: rust