dtolnay / async-trait

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

Using self method in default implementation is not supported #200

Closed stevenroose closed 2 years ago

stevenroose commented 2 years ago

I can't find an issue for this, but it seems that this example is not supported:

use async_trait::async_trait;

#[async_trait]
pub trait Test {
    async fn normal(&self) -> bool;

    async fn with_default(&self) -> bool {
        self.normal()
    }
}
dtolnay commented 2 years ago

For calling one async function from another async function, you need to use await (in general, not only inside async traits):

async fn with_default(&self) -> bool {
    self.normal().await
}
stevenroose commented 2 years ago

Is it correct that that makes the futures returned no longer Send?