Open SylvainGarrigues opened 4 months ago
Oddly enough, I noticed that in my case, manually specifying the default
function to Default::default()
makes the code compile without restraining T
to implement Default
:
#[serde(skip_deserializing, default = "Default::default")]
This is because serde_derive constraints generic types of the struct (T
) to required traits instead of actual types of fields (Option<T>
).
And perhaps this ^ is a bug? I faced the same problem with serde(default) attribute for a field of custom generic type, which implements Default.
Using the explicit path does not help either:
Quoting the documentation for
#[serde(skip_deserializing)]
: When deserializing, Serde will useDefault::default()
or the function given bydefault = "..."
to get a default value for this field.Option<T>
defaults toNone
event ifT
doesn't implementDefault
, so why does the compiler complainT
must implement suchDefault
trait for me to be able to deriveDeserialize
?Sample code (uncomment
/* Default */
to have the code compile):Same code in Rust playground