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

Make rpc::Client and SubscriptionClient traits usable in wasm #1385

Closed
jstuczyn opened this issue Dec 14, 2023 · 4 comments · Fixed by #1386
Closed

Make rpc::Client and SubscriptionClient traits usable in wasm #1385

jstuczyn opened this issue Dec 14, 2023 · 4 comments · Fixed by #1386
Labels
enhancement New feature or request

Comments

@jstuczyn
Copy link
Contributor

Description

Currently it's impossible to implement those traits in wasm as by default async_trait imposes the Send bound. This, however, makes it unusable in wasm. Therefore I propose introducing conditional compilation based on target:

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait Client { ... }

Definition of "done"

@romac
Copy link
Member

romac commented Dec 14, 2023

Thanks for the issue and associated PR, looks good!

For my own knowledge, would mind going into a bit more detail as to why Send bounds on result types of desugared async fns prevents implemented them when targeting WASM? I am asking because that's the first time I hear about that and I am genuinely interested in understanding why.

@jstuczyn
Copy link
Contributor Author

jstuczyn commented Dec 15, 2023

Hi, I'm extremely glad you asked because turns out there was a bit of misunderstanding on my end. It's actually not a wasm32 target-wide issue, but is related to the futures created by wasm-bindgen that are then run in the browser: rustwasm/wasm-bindgen#2833 I've been dealing with those for so long that I forgot other targets exist 😅 So I assume that, for example, under wasm32-wasi this isn't a problem at all. So perhaps, rather than making the trait boundary be target locked, a feature-lock solution would be more appropriate. What do you reckon?

@tony-iqlusion
Copy link
Collaborator

AFIT is shipping in Rust 1.75, FWIW. That's a couple weeks away and will obsolete async-trait.

@romac
Copy link
Member

romac commented Dec 18, 2023

I'd rather avoid adding one more feature flag for the moment, so let's merge this as-is for now and we can revisit once Rust 1.75 is out and we decide to bump the MSRV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants