Is there is any way to dynamically dispatching for async trait?

Defined this async trait:

pub trait Storer{
    async fn find(&self, id:String) ->Vec<Item> {
        todo!()
    }
}

I want use like this:

async fn do_find(storer: &dyn Storer, id: String) {
}

Or use generic:

async fn do_find<T:Storage>(storer: T, id: String) {

}

But it both not works.

The second one does work.

But traits with async functions can't be dyn Traits. Use async_trait if you need that.

3 Likes