Problems caused by async trait

Indeed, as this error message tells you, traits with impl Trait return types (or async fn) are not object safe. If you need trait objects, for async fn the most convenient option is probably still async_trait - Rust, for other traits in return values, you’d need to use e.g. Box<dyn Trait> manually.

See also the blog post on the feature

If common use-cases don’t involve trait objects and you don’t want to change the trait itself for efficientcy of such use-cases, it can also always be an option to only wrap around the trait to make it object safe just for the use-cases you need; see also this answer I wrote in a different thread about object safety today:

2 Likes