logoalt Hacker News

dhosekyesterday at 9:13 PM2 repliesview on HN

The gotcha is what happens when TypeWithSomeSerialization is not something you’re using directly but is contained within SomeOtherTypeWithSomeSerialization which you are using directly. Then things get messy.


Replies

deathanatostoday at 1:40 AM

We can't say with certainty how an unspecified in-the-future library might work, so I'm going to use serde as a stand-in.

You can implement `Serialize` for a wrapper type and still serialize `SomeOtherTypeWithSomeSerialization` (which might be used by the type being wrapper directly or indirectly) differently. It might not be derivable, of course, but "I don't want the default" sort of makes that a given.

bigfishrunningtoday at 12:14 AM

In that case, wrap a reference maybe?

    pub struct TypeWithDifferentSerialization(&TypeWithSomeSerialization)