用途:这是一个 Rust 异步错误排查技能,用于在编译器或运行时抛出异步相关错误时,定位隐藏原因并给出对应修复。核心观点是异步错误通常不是 async/.await 本身的问题,而是 Send、Pin、生命周期或运行时策略违规,因为 async fn 会被展开为匿名状态机 Future。
主要能力:按五类错误路由。一、future 非 Send:!Send 值跨 .await 存活,修复为用作用域提前释放、改用 tokio::sync::Mutex,或将 Rc 换为 Arc。二、Pin/Unpin 错误:!Unpin 自引用 future 被移动,修复为 Box::pin、std::pin::pin! 或 tokio::pin!。三、async fn 内生命周期错误:返回的 future 捕获全部输入生命周期,修复为取 owned 参数、显式命名生命周期,或在首个 .await 前结束借用。四、trait 中 async fn:静态分发可用原生 AFIT,dyn Trait 或需要 Send 约束时用 #[async_trait] 或手写 Pin<Box<dyn Future>>。五、运行时阻塞与嵌套运行时:嵌套 Runtime::new().block_on 会 panic,应直接 .await 或用 Handle::current();阻塞调用会饿死执行器,应改用 tokio::time::sleep、tokio::fs 或 spawn_blocking。
使用方式:当出现 future cannot be sent between threads safely、future is not Send、cannot move out of pinned、is not Unpin、async fn 内生命周期错误、Cannot start a runtime from within a runtime,或异步程序挂起时使用。技能提供错误分类路由表与修复选择决策树,并附 methods、examples、anti-patterns 参考文件。
限制:资料未提供安装命令、收费方式与具体平台信息,暂未提供。