this post was submitted on 22 Jan 2026
20 points (100.0% liked)

Rust

7695 readers
29 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
 

I just ran into the wonderful error message

the trait is not dyn compatible because method publish_video is async

and boy, what a rabbit hole. I found out about async_trait which resolves this by turning async methods into fn method() -> Pin<Box<dyn Future + Send + 'async_trait>>, but I thought that's what the async fn was syntax sugar for??? Then I ran into this member-only medium post claiming

Rust Async Traits: What Finally Works Now

Async functions in traits shipped. Here’s what that means for your service interfaces.

But I clicked through every rust release since 1.75.0 where impl AsyncTrait was shipped and couldn't find a mention of async. Now I'm just confused (and still using async_trait). Hence the question above...

you are viewing a single comment's thread
view the rest of the comments
[–] hallettj@leminal.space 1 points 3 days ago

I'm not informed on all the details, but a key difference between the async_trait macro and a native async keyword is that async_trait gives you that boxed, trait object type. IIUC the thinking is native support should not automatically box futures, which implies it shouldn't use dyn either. Using Box and dyn is an easy way to make sure the code works no matter what type of future a method returns. But the trade-off is some runtime overhead from heap allocation (due to Box), and dynamic dispatch (due to dyn).

According to areweasyncyet.rs:

async fn in trait method not stabilized yet

  • Workaround is available as an attribute macro: async-trait