dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

opt out of Send for wasm only #159

Closed ctaggart closed 3 years ago

ctaggart commented 3 years ago

Hi @dtolnay 👋🏻 ,

I am trying to build https://github.com/Azure/azure-sdk-for-rust/pull/228 for wasm, but I ran into a problem where wasm should not have the Send markers. This does not work, but what I roughly want to do is:

cfg_if::cfg_if! {
    if cfg(target_arch = "wasm32") {
        #[async_trait(?Send)]
    } else {
        #[async_trait]
    }
}

Any suggestions on how to solve this predicament?

taiki-e commented 3 years ago

I think cfg_attr would work. Something like the following:

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]