我正在尝试使用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
如何在字段中指定类型?有什么明显的我想念的吗?
答案 0 :(得分:1)
语法如下:
Scene<Renderer = YourRenderer>