Skip to content

azure_core::Model derive macro doesn't infer Deserialize bounds in impl #1803

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

Open
analogrelay opened this issue Sep 16, 2024 · 1 comment · May be fixed by #2559
Open

azure_core::Model derive macro doesn't infer Deserialize bounds in impl #1803

analogrelay opened this issue Sep 16, 2024 · 1 comment · May be fixed by #2559
Labels
Azure.Core The azure_core crate
Milestone

Comments

@analogrelay
Copy link
Member

The derive macro for Model doesn't work for generic arguments. For example, this doesn't work:

#[derive(Model, Deserialize)]
pub struct Wrapper<T> {
    items: Vec<T>,
}

This is because our logic generates an impl like this:

impl<T> Model for Wrapper<T> {
}

But, serde's Deserialize derive macro generates this (effectively):

impl<T: Deserialize> Deserialize for Wrapper<T> {
}

Since our Model impl depends on the impl of Deserialize, we end up with an error:

the trait bound `T: Deserialize<'_>` is not satisfied
required for `container_client::Wrapper<T>` to implement `DeserializeOwned`

What we'd need to do is add logic to our derive macro that matches serde's logic to guess appropriate type parameter bounds for the impl. This isn't really blocking, since one can manually implement Model without too much trouble in this case. For example:

impl<M: DeserializeOwned> azure_core::Model for QueryResponseModel<M> {
    async fn from_response_body(
        body: azure_core::ResponseBody,
    ) -> typespec_client_core::Result<Self> {
        body.json().await
    }
}
@analogrelay
Copy link
Member Author

Logging this because I hit it in implementing a query API for Cosmos. I'm working around it with the work-around posted above, but I wanted to track this issue for future reference (and to hopefully fix it later)

@github-project-automation github-project-automation bot moved this to Untriaged in Azure SDK Rust Feb 5, 2025
@RickWinter RickWinter added the Azure.Core The azure_core crate label Mar 6, 2025
@RickWinter RickWinter added this to the Backlog milestone Mar 6, 2025
@RickWinter RickWinter moved this from Untriaged to Backlog in Azure SDK Rust Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core The azure_core crate
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants