Allow non-Serialize default values.

Default values that don't implement Serialize are now ignored, rather than causing a compile error.
This is done by simulating specialization using a technique copied from Rocket:
5ebefa97c9/core/lib/src/sentinel.rs (L391-L445)

Fixes #115
This commit is contained in:
Graham Esau 2021-11-14 19:16:46 +00:00
parent 6f39a13724
commit 690fe44343
4 changed files with 46 additions and 4 deletions

View file

@ -68,7 +68,7 @@ impl<'a> SchemaMetadata<'a> {
if let Some(default) = &self.default {
setters.push(quote! {
default: #default.and_then(|d| schemars::_serde_json::value::to_value(d).ok()),
default: #default.and_then(|d| schemars::_schemars_maybe_to_value!(d)),
});
}