Kisis
Kisis

Reputation: 53

Required lifetime parameter on array of vec

So everytime I run this :

static LAYERS_NB : u32 = 50;

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

I get this error :

error[E0106]: missing lifetime specifier
  --> src/display.rs:12:18
   |
12 |     layers: [Vec<render::Texture>;LAYERS_NB],
   |                  ^^^^^^^^^^^^^^^ expected lifetime parameter

Texture is a structure from the SDL2 wrapper library of Rust. I don't understand why he is asking me a lifetime since my Struct doesn't own any references. Can somebody explain me why ?

Thanks !

Upvotes: 0

Views: 136

Answers (1)

edwardw
edwardw

Reputation: 14002

Well, sdl2::render::Texture does have a lifetime parameter, so your struct containing it also has to have one. And the size of an array needs to be a constant usize:

const LAYERS_NB: usize = 50;

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

The Rust compiler is generally very good at telling you what is wrong. Try read the diagnosis.

Upvotes: 2

Related Questions