Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add #[worker::trait_send] for async_trait #544

Open
1 task done
Enduriel opened this issue Apr 11, 2024 · 0 comments
Open
1 task done

[Feature] Add #[worker::trait_send] for async_trait #544

Enduriel opened this issue Apr 11, 2024 · 0 comments

Comments

@Enduriel
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description

This is an ergonomics problem for when I have to implement a trait using async_trait when passing JsValues, right now in order to make it work I have to do something like

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

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 which requires implementing async traits

@Enduriel Enduriel changed the title [Feature] Add #[worker::send] for async_trait [Feature] Add #[worker::trait_send] for async_trait Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant