gpt4 book ai didi

rust - vec数组上的必需生存期参数

转载 作者:行者123 更新时间:2023-12-03 11:43:29 25 4
gpt4 key购买 nike

所以每次我运行这个:

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

Texture是Rust的SDL2包装器库中的结构。我不明白他为什么要问我一辈子,因为我的Struct没有任何引用。
有人可以解释我为什么吗?

谢谢 !

最佳答案

好吧, sdl2::render::Texture 确实有一个生命周期参数,因此包含它的结构也必须有一个。并且数组的大小需要为常数usize:

const LAYERS_NB: usize = 50;

struct Layers<'a> {
layers: [Vec<render::Texture<'a>>; LAYERS_NB],
}

Rust编译器通常非常擅长告诉您出了什么问题。尝试阅读诊断。

关于rust - vec数组上的必需生存期参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59800689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com