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

Improve Serialize of adjacently tagged newtype variants #1227

Merged
merged 1 commit into from Apr 21, 2018
Merged

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Apr 21, 2018

The existing implementation was unnecessarily complicated.

struct __AdjacentlyTagged<'__a> {
    data: (&'__a String,),
    phantom: _serde::export::PhantomData<AdjacentlyTagged>,
}
impl<'__a> _serde::Serialize for __AdjacentlyTagged<'__a> {
    fn serialize<__S>(
        &self,
        __serializer: __S,
    ) -> _serde::export::Result<__S::Ok, __S::Error>
    where
        __S: _serde::Serializer,
    {
        let (__field0,) = self.data;
        _serde::Serialize::serialize(__field0, __serializer)
    }
}
_serde::ser::SerializeStruct::serialize_field(
    &mut __struct,
    "content",
    &__AdjacentlyTagged {
        data: (__field0,),
        phantom: _serde::export::PhantomData::<AdjacentlyTagged>,
    },
)?;

Instead the new implementation does simply:

_serde::ser::SerializeStruct::serialize_field(
    &mut __struct,
    "content",
    __field0,
)?;

Fixes #1224.

The existing implementation was unnecessarily complicated.

    struct __AdjacentlyTagged<'__a> {
        data: (&'__a String,),
        phantom: _serde::export::PhantomData<AdjacentlyTagged>,
    }
    impl<'__a> _serde::Serialize for __AdjacentlyTagged<'__a> {
        fn serialize<__S>(
            &self,
            __serializer: __S,
        ) -> _serde::export::Result<__S::Ok, __S::Error>
        where
            __S: _serde::Serializer,
        {
            let (__field0,) = self.data;
            _serde::Serialize::serialize(__field0, __serializer)
        }
    }
    _serde::ser::SerializeStruct::serialize_field(
        &mut __struct,
        "content",
        &__AdjacentlyTagged {
            data: (__field0,),
            phantom: _serde::export::PhantomData::<AdjacentlyTagged>,
        },
    )?;

Instead the new implementation does simply:

    _serde::ser::SerializeStruct::serialize_field(
        &mut __struct,
        "content",
        __field0,
    )?;
@dtolnay dtolnay merged commit 1a972d2 into master Apr 21, 2018
@dtolnay dtolnay deleted the ser branch April 21, 2018 19:10
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.

None yet

1 participant