serde icon indicating copy to clipboard operation
serde copied to clipboard

`[serde(default = .. )]` in deep path

Open magic-akari opened this issue 3 years ago • 1 comments

Playground

I'm not sure if it's a bug or a design. I expect it to print consistent results in both cases. (Config { point: Point { x: MyInt(0), y: MyInt(1) } })

magic-akari avatar Feb 28 '22 06:02 magic-akari

You are doing two different things here, which is why you get the different results. In the first case the Point struct is provided, but all fields are missing, thus they get filled by the default values on the fields, i.e., MyInt::default and MyInt::one. In the second case the Point struct is missing and gets filled by Point::default. The derived Default implementation uses MyInt::default in both cases.

If you want to change the Default implementation of Point you need to implement it manually instead of deriving it.

jonasbb avatar Feb 28 '22 08:02 jonasbb