dtolnay / async-trait

Type erasure for async trait methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lifetime bounds on method do not match the trait declaration

Shell1010 opened this issue · comments

Using an impl like this, where DataStruct uses the enum_dispatch crate.

#[async_trait]
pub trait Request {
    fn req(&self) -> reqwest::Client {
        reqwest::Client::new()
    }

    async fn fetch(&self) -> Result<DataStruct, TflError>;
    
}

#[enum_dispatch]
pub trait JsonTrait {
    fn todo(&self) -> &str { 
        "foo"
    }
}

#[derive(Debug, Deserialize, Serialize)]
#[enum_dispatch(JsonTrait)]
pub enum DataStruct {
    ...
}

impl Request for Client {
    async fn fetch(&self) -> Result<DataStruct, TflError> {
        ...
    }
}

I get the following error.

error[E0195]: lifetime parameters or bounds on method `fetch` do not match the trait declaration
  --> lines/src/client.rs:54:19
   |
22 |     async fn fetch(&self) -> Result<DataStruct, TflError>;
   |     -----    ------------ lifetimes in impl do not match this method in trait
   |     |
   |     this bound might be missing in the impl
...
54 |     async fn fetch(&self) -> Result<DataStruct, TflError> {
   |                   ^ lifetimes do not match method in trait

Perhaps I do not understand something. Apologies if this is obvious.

My bad, it seems someone already referenced this in #243. Closing this issue.