Skip to content

Commit d8b6119

Browse files
authored
fix async_trait on wasm32
1 parent 81f41d7 commit d8b6119

File tree

1 file changed

+8
-4
lines changed
  • sdk/typespec/typespec_client_core/src/http

1 file changed

+8
-4
lines changed

sdk/typespec/typespec_client_core/src/http/format.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ pub trait Format {}
1818
///
1919
/// This trait defines the `deserialize_with` method, which takes a [`ResponseBody`] and returns the deserialized value.
2020
/// The `F` type parameter allows for different implementations of the `deserialize_with` method based on the specific [`Format`] marker type used.
21-
#[async_trait::async_trait]
21+
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
22+
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
2223
pub trait DeserializeWith<F: Format>: Sized {
2324
async fn deserialize_with(body: ResponseBody) -> typespec::Result<Self>;
2425
}
2526

2627
/// Implements [`DeserializeWith<T>`] for [`ResponseBody`], by simply returning the body stream as is.
27-
#[async_trait::async_trait]
28+
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
29+
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
2830
impl<T: Format> DeserializeWith<T> for ResponseBody {
2931
async fn deserialize_with(body: ResponseBody) -> typespec::Result<Self> {
3032
Ok(body)
@@ -33,7 +35,8 @@ impl<T: Format> DeserializeWith<T> for ResponseBody {
3335

3436
/// Implements [`DeserializeWith<DefaultFormat>`] for an arbitrary type `D`
3537
/// that implements [`serde::de::DeserializeOwned`] by deserializing the response body to the specified type using [`serde_json`].
36-
#[async_trait::async_trait]
38+
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
39+
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
3740
impl<D: DeserializeOwned> DeserializeWith<DefaultFormat> for D {
3841
async fn deserialize_with(body: ResponseBody) -> typespec::Result<Self> {
3942
body.json().await
@@ -57,7 +60,8 @@ pub struct XmlFormat;
5760
impl Format for XmlFormat {}
5861

5962
#[cfg(feature = "xml")]
60-
#[async_trait::async_trait]
63+
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
64+
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
6165
impl<D: DeserializeOwned> DeserializeWith<XmlFormat> for D {
6266
async fn deserialize_with(body: ResponseBody) -> typespec::Result<Self> {
6367
body.xml().await

0 commit comments

Comments
 (0)