Generic struct declaration with lifetime

Playground 1: Rust Playground

Playground 2: Rust Playground

Syntax problem. I'm trying to declare a struct that has both generic and lifetime parameters. If I write

struct RenderScene<T> {
    client: &T
}

the compiler correctly reports

error[E0106]: missing lifetime specifier
 --> src/lib.rs:4:13
  |
4 |     client: &T
  |             ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
3 ~ struct RenderScene<'a, T> {
4 ~     client: &'a T
  |

But if I use the compiler-suggested syntax, which seems reasonable, I get the error in Playground 2:

  | struct RenderScene<'a T> {
  |                       ^ expected one of `,`, `:`, or `>`

So how to write that?

As the compiler says, you're missing a comma.

2 Likes