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…

  • Starfighter@discuss.tchncs.de
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    16 hours ago

    I ran into the same issue not so long ago and at least for no_std I had to resort to using the async_trait crate. (The project is no_std but has alloc)

    I can’t recall the exact error so it might have been due to mixing async and non-async methods in the same trait. I would have to look at it again…

    • BB_C@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      15 hours ago

      dyn compatibility of the trait itself is another matter. In this case, an async method makes a trait not dyn-compatible because of the implicit -> impl Future opaque return type, as documented here.

      But OP didn’t mention whether dyn is actually needed or not. For me, dyn is almost always a crutch (exceptions exist).