API Reference
async-trait
Provides async fn in traits for Rust by desugaring them into boxed futures, enabling async trait objects.
Official Documentation ↗CompatibilityThis documentation covers version
v0.1. Check the official docs for the latest API surface.Installation
cargo
cargo add async-traitMethods
No methods match this filter.
async-trait rewrites async trait methods into methods returning boxed pinned futures.
Key Features
- async fn in trait definitions
- Consistent across trait and impl
- Works with dyn dispatch
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/async-trait/latest/async_trait/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:11.253Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Please file an issue if you see unexpected borrow checker errors, type errors, or warnings. (https://docs.rs/async-trait/latest/async_trait/)
- Fortunately the compiler is able to diagnose missing lifetimes with a good error message. (https://docs.rs/async-trait/latest/async_trait/)
FAQ
- Why is it needed?
- Rust did not allow async fn in traits before native support matured; the macro desugars them into boxed futures.
- What is the cost?
- Each call allocates a boxed future. For hot paths consider an enum of concrete types instead of dynamic dispatch.
- Do I need it with newer Rust?
- Native async fn in traits exists now, but it does not yet cover dyn dispatch equally, so the macro remains common for objects.
Report a problem with this API docOpens a pre-filled issue on GitHub.