You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I have to define a newtype (eg: "BoolDefaultTrue") every time I want an optional struct field to have a non-Default::default() default, which is clumsy. Ideally I could just say something like:
structFoo{#[serde(default=true)]enabled:bool,}
... and this would fill in the value true if it was missing from the serialised string. Super-awesome would be if serde also generated a Default trait implementation for Foo that respected the same values, but I could understand that being considered out of scope.
The text was updated successfully, but these errors were encountered:
@erickt: is using the surrounding type's Default impl (if present) too much magic? Alternatively requiring that the type impls Default if any field is annotated would be a breaking change and maybe not what one expects when annotating a field.
Currently I have to define a newtype (eg: "BoolDefaultTrue") every time I want an optional struct field to have a non-Default::default() default, which is clumsy. Ideally I could just say something like:
... and this would fill in the value
true
if it was missing from the serialised string. Super-awesome would be if serde also generated aDefault
trait implementation forFoo
that respected the same values, but I could understand that being considered out of scope.The text was updated successfully, but these errors were encountered: