dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

lifetimes do not match method in trait #268

Closed king-11 closed 4 months ago

king-11 commented 4 months ago

Thanks for this crate first of all helps a lot with async code recently discovered it.

I wrote below trait

#[async_trait]
pub trait SourceFactory: Send + Sync {
    async fn get_source(
        &self,
        start_block: u32,
    );
}

While implementing it here

pub struct FileSourceFactory {}

impl SourceFactory for FileSourceFactory {
    async fn get_source(
            &self,
            _start_block: u32,
        ) {
    }
}

it throws error that

lifetime parameters or bounds on method `get_source` do not match the trait declaration
dtolnay commented 4 months ago

That code is missing #[async_trait] on the impl.

king-11 commented 4 months ago

ohh got it thanks. really sorry for opening this silly issue and not reading through the docs first I thought just adding to trait was sufficient as per the macro name. do you think its possible to just have it their instead as a new feature in future?