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

Skip serializing generic still requires the bound #2727

Open
irevoire opened this issue Apr 10, 2024 · 0 comments
Open

Skip serializing generic still requires the bound #2727

irevoire opened this issue Apr 10, 2024 · 0 comments

Comments

@irevoire
Copy link

Hello,

I noticed that the serde derive macro was incorrectly adding impl Serialize bounds to the structures that derive Serialize:

use serde::Serialize;

#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct First<Http> {
    second: Second<Http>,
}

#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Second<Http> {
    nb: usize,
    #[serde(skip_serializing)]
    http_client: Http,
}

pub struct Truc;

fn main() {
    // This works, serde understands that `Http` doesn't need to implement `Serialize`
    let a = serde_json::to_string_pretty(&Second {
        nb: 1,
        http_client: Truc,
    })
    .unwrap();

    // This doesn't; serde derive added a bound requiring that `Http` implements `Serialize`
    let a = serde_json::to_string_pretty(&First {
        second: Second {
            nb: 1,
            http_client: Truc,
        },
    })
    .unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant