cloudflare / cloudflare/workers-rs
[Feature] Add #[worker::trait_send] for async_trait
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 429
- Avg merge
- 20h 28m
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Description
This is an ergonomics problem for when I have to implement a trait using [async_trait](https://docs.rs/async-trait/latest/async_trait/) when passing JsValues, right now in order to make it work I have to do something like
```rs
struct MyStruct {
db: D1Database
}
#[worker::send]
async fn do_foo(value: &MyStruct) {
// run logic
}
#[async_trait::async_trait]
impl SomeAsyncTrait for MyStruct {
fn foo(&self) {
do_foo(self).await;
}
}
```
Where it would be much nicer and more readable to be able to do something like this, which should probably be behind an `async_trait` feature flag
```rs
struct MyStruct {
db: D1Database
}
#[async_trait::async_trait]
impl SomeAsyncTrait for MyStruct {
#[worker::trait_send]
async fn foo(&self) {
// run logic
}
}
```
I have next to no experience in writing Rust macros, and at a quick glance there's more going on here than I'd be easily able to dig through and understand with my lacking experience, so I hope someone picks this up since we can now easily use [axum-login](https://github.com/maxcountryman/axum-login) which requires implementing async traits
Contributor guide
Assessment
This issue has not been assessed yet.