所以每次我运行这段代码:
static LAYERS_NB : u32 = 50;
struct Layers{
layers: [Vec<render::Texture>;LAYERS_NB],
}
我得到了这个错误:
error[E0106]: missing lifetime specifier
--> src/display.rs:12:18
|
12 | layers: [Vec<render::Texture>;LAYERS_NB],
| ^^^^^^^^^^^^^^^ expected lifetime parameter
纹理是Rust的SDL2包装库中的一种结构。我不明白,既然我的Struct没有任何推荐信,为什么他要问我一生。有人能给我解释一下原因吗?
谢谢!
发布于 2020-01-18 21:30:24
嗯,sdl2::render::Texture
确实有一个生命周期参数,所以包含它的结构也必须有一个。并且数组的大小需要是常量usize
const LAYERS_NB: usize = 50;
struct Layers<'a> {
layers: [Vec<render::Texture<'a>>; LAYERS_NB],
}
Rust编译器通常非常擅长于告诉您哪里出了问题。试着读一下诊断报告。
https://stackoverflow.com/questions/59800689
复制相似问题