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

feat(codegen): Inhibit generic bounds if skip_serializing #260

Merged
merged 2 commits into from
Apr 12, 2016
Merged

feat(codegen): Inhibit generic bounds if skip_serializing #260

merged 2 commits into from
Apr 12, 2016

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Feb 29, 2016

Addresses part of #197.

The generated code for a struct like:

struct Test<A, B, C> {
    a: X<A>,
    #[serde(skip_serializing)]
    b: B,
    #[serde(serialize_with="...")]
    c: C,
}

Used to be:

impl<A, B, C> Serialize for Test<A, B, C>
    where A: Serialize,
          B: Serialize,
          C: Serialize,
{ ... }

Now it is:

impl<A, B, C> Serialize for Test<A, B, C>
    where X<A>: Serialize,
{ ... }

Both skip_serializing and serialize_with mean the type does not need to implement Serialize.

The remaining work for #197 is to add a skip_deserializing attribute that does the equivalent for Deserialize (also filed as #259), and to infer T: Default appropriately.

The generated code for a struct like:

    struct Test<A, B, C> {
        a: X<A>
        #[serde(skip_serializing)]
        b: B
        #[serde(serialize_with="...")]
        c: C
    }

Used to be:

    impl<A, B, C> Serialize for Test<A, B, C>
        where A: Serialize,
              B: Serialize,
              C: Serialize,
    { ... }

Now it is:

    impl<A, B, C> Serialize for Test<A, B, C>
        where X<A>: Serialize,
    { ... }

Both `skip_serializing` and `serialize_with` mean the type does not need to
implement `Serialize`.
@dtolnay
Copy link
Member Author

dtolnay commented Feb 29, 2016

It looks like this works on beta and nightly but not stable because it depends on rust-lang/rust#30389. I will need to either omit bounds for types that do not involve type parameters, or revert to the old behavior on <1.7.0.

@dtolnay
Copy link
Member Author

dtolnay commented Mar 1, 2016

I have added additional filtering to make this work with <1.7.0.

@erickt erickt merged commit eaff73a into serde-rs:master Apr 12, 2016
@erickt
Copy link
Member

erickt commented Apr 12, 2016

@dtolnay: This was awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants