This question already has answers here:
Why must the associated type be specified in a collection of references to types implementing a trait?
(3个答案)
2年前关闭。
我正在尝试使用trait作为我的结构中的字段:
当我尝试使用它时,出现错误:
如何在字段中指定类型?有什么明显的我想念的东西吗?
(3个答案)
2年前关闭。
我正在尝试使用trait作为我的结构中的字段:
pub trait Scene {
type Renderer;
fn update(&mut self);
fn render(&mut self, r: &mut Self::Renderer);
}
struct Example {
active_scene: *mut Scene,
}
当我尝试使用它时,出现错误:
error[E0191]: the value of the associated type `Renderer` (from the trait `Scene`) must be specified
--> src/lib.rs:9:24
|
9 | active_scene: *mut Scene,
| ^^^^^ missing associated type `Renderer` value
如何在字段中指定类型?有什么明显的我想念的东西吗?
最佳答案
语法如下:
Scene<Renderer = YourRenderer>
关于rust - 如何为特征参数指定类型? [复制],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53970995/
10-11 23:04