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

WIP: refactor: migrate to native async trait #1268

Closed
wants to merge 2 commits into from

Conversation

niklasad1
Copy link
Member

Close #1229

This PR removes all usage of the async trait crate to get rid of a bunch extra allocations for boxing each future.
In order to make it work this PR modifies the original async methods to add send bounds to each method.

#[rpc(server, client)]
pub trait Rpc
{
	#[method(name = "async")]
	async fn async(
		&self,
	) -> Result<Vec<u8>, ErrorObjectOwned>;

	#[method(name = "sync")]
	fn sync(
		&self,
	) -> Result<Vec<u8>, ErrorObjectOwned>;
}

-> the actual generated trait for the server is:

#[rpc(server)]
pub trait RpcServer
{
	fn async(
		&self,
	) -> impl Future<Output = Result<Vec<u8>, ErrorObjectOwned>> + Send;

	fn sync(
		&self,
	) -> Result<Vec<u8>, ErrorObjectOwned>;
}

-> the actual generated trait for the client is:

#[rpc(server)]
pub trait RpcClient
{
	fn async(
		&self,
	) -> impl Future<Output = Result<Vec<u8>,  client::Error>> + Send;

	fn sync(
		&self,
	) -> impl Future<Output = Result<Vec<u8>, client::Error>> + Send;
}

I noticed that there is already a crate that helps with these conversions which make more ergonomic to implement for users, https://docs.rs/trait-variant/latest/trait_variant/attr.make.html

@niklasad1 niklasad1 closed this Feb 6, 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

Successfully merging this pull request may close these issues.

Drop async_trait in favor of native async traits
1 participant