Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Look at the extremely popular async_trait macro crate: https://crates.io/crates/async-trait .

What it does under the hood is to box everything. See https://github.com/dtolnay/async-trait#explanation

You would think that you should be able to desugar async traits to something that does not need to box. But this is not possible with stable rust.

There is an effort to make this possible. See for example this discussion here: https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-i...

Initially it was thought that Send bounds would not be needed, but community feedback strongly suggests that Send is indeed needed.

https://blog.rust-lang.org/inside-rust/2023/05/03/stabilizin...

All this is a real problem, and not just a "you are holding it wrong" problem.

Edit: here is the - still open - issue about higher-ranked lifetime errors: https://github.com/rust-lang/rust/issues/102211



Yes, it currently needs to box. But again, Sync is just a symptom of the real issues here (async fns have unpronouncable return types, opaque return types (impl trait) isn't supported in traits, and we don't have a good syntax for expressing constraints on opaque return types). Getting rid of Sync wouldn't fix any of those issues.


You don't get weird higher-ranked lifetime errors when you use non Sync futures with hand-rolled async traits.

I am not saying that this is the reason to use local futures. But if you have decided that local futures are the way to go anyway, it's a nice benefit.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: