Brady Dean
Brady Dean

Reputation: 3573

Implementing struct that has lifetimes

Here's my code:

struct Server<'a> {
    port: &'a u16,
}

impl Server {
    fn connect() {
        //stuff
    }
}

The error I'm getting is with the impl block:

error: wrong number of lifetime parameters: expected 1, found 0 [E0107]

I had to add a lifetime parameter to Server to allow the u16 slice but I do not know how to add one for an impl block.

Upvotes: 6

Views: 2021

Answers (1)

Jorge Israel Pe&#241;a
Jorge Israel Pe&#241;a

Reputation: 38576

You need to have the lifetime annotation on the implementation as well.

impl<'a> Server<'a> {
    fn connect() {
        //stuff
    }
}

Upvotes: 7

Related Questions