Skip to content

Commit

Permalink
add alternate impls of from_response_body for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay authored Sep 30, 2024
1 parent fbf3880 commit fbcf72f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdk/cosmos/azure_data_cosmos/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ impl<T> Item<T> {
// So we have to manually implement Model
// See https://github.com/Azure/azure-sdk-for-rust/issues/1803
impl<T: DeserializeOwned> Model for Item<T> {
#[cfg(not(target_arch = "wasm32"))]
fn from_response_body(
body: azure_core::ResponseBody,
) -> impl std::future::Future<Output = typespec_client_core::Result<Self>> + Send + Sync {
body.json()
}

#[cfg(target_arch = "wasm32")]
fn from_response_body(
body: azure_core::ResponseBody,
) -> impl std::future::Future<Output = typespec_client_core::Result<Self>> {
body.json()
}
}

fn deserialize_cosmos_timestamp<'de, D>(deserializer: D) -> Result<Option<OffsetDateTime>, D::Error>
Expand Down
6 changes: 6 additions & 0 deletions sdk/typespec/typespec_client_core/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ pub trait Model: Sized {

// Allow for deserializing into "raw" JSON.
impl Model for serde_json::Value {
#[cfg(not(target_arch = "wasm32"))]
fn from_response_body(
body: ResponseBody,
) -> impl Future<Output = crate::Result<Self>> + Send + Sync {
body.json()
}

#[cfg(target_arch = "wasm32")]
fn from_response_body(body: ResponseBody) -> impl Future<Output = crate::Result<Self>> {
body.json()
}
}

/// An HTTP response.
Expand Down

0 comments on commit fbcf72f

Please sign in to comment.