Registry / async / async-trait

async-trait

JSON →
library0.1.89rscratesunverified

Type erasure for async trait methods

# Cargo.toml [dependencies] async-trait = "0.1.89"
INSTALL
IMPORT
SIG · ASYNC-TRAIT
A
async-trait
asyncrustv0.1.89
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

async_trait
✓ use async_trait::async_trait;

Defines an async trait and implements it.

use async_trait::async_trait; #[async_trait] pub trait MyTrait { async fn do_something(&self); } struct MyStruct; #[async_trait] impl MyTrait for MyStruct { async fn do_something(&self) { println!("Done!"); } } #[tokio::main] async fn main() { let s = MyStruct; s.do_something().await; }
Debug
Known issues
gotchaRequires an async runtime (e.g., tokio) to execute the async methods.
fix
Add tokio as a dependency and use #[tokio::main] or another runtime.
affects: >=0.1.0
Upgrade
Version history
0.1.89latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
38
OpenAI (training)
1
Resources
async-trait — cargo add async-trait · libregistry