Dyn-Compatible Async Traits in Rust: Why the Manual Boxed Future Idiom is Required

Pin> in Traits - Why the Manual Desugar? Context When a Rust trait needs async methods and must be usable as a trait object ( Box , &dyn Trait , Arc ), you cannot just write async fn and move on. async fn in traits returns an opaque impl Future whose concrete type differs per implementation - which breaks vtable dispatch. The compiler's own error-recovery hint spells it out: to make this trait dyn-compatible, use -> Pin + Send>> inste

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论