Less indentiation in deserialize_from_body

This commit is contained in:
David Tolnay
2017-12-10 23:04:44 -08:00
parent ccae35d92a
commit 85e3ddc2b8
2 changed files with 22 additions and 14 deletions
+13 -14
View File
@@ -266,24 +266,23 @@ fn deserialize_from_body(cont: &Container, params: &Parameters) -> Option<Fragme
// for remote derives. // for remote derives.
assert!(!params.has_getter); assert!(!params.has_getter);
if cont.body.all_fields().all(|field| field.attrs.deserialize_with().is_some()) { if cont.attrs.from_type().is_some()
|| cont.attrs.identifier().is_some()
|| cont.body.all_fields().all(|f| f.attrs.deserialize_with().is_some())
{
return None; return None;
} }
if let (None, attr::Identifier::No) = (cont.attrs.from_type(), cont.attrs.identifier()) { match cont.body {
match cont.body { Body::Enum(_) => None,
Body::Enum(_) => None, Body::Struct(Style::Struct, ref fields) => {
Body::Struct(Style::Struct, ref fields) => { Some(deserialize_from_struct(None, params, fields, &cont.attrs, None, Untagged::No))
Some(deserialize_from_struct(None, params, fields, &cont.attrs, None, Untagged::No))
}
Body::Struct(Style::Tuple, ref fields) |
Body::Struct(Style::Newtype, ref fields) => {
Some(deserialize_from_tuple(None, params, fields, &cont.attrs, None))
}
Body::Struct(Style::Unit, _) => None,
} }
} else { Body::Struct(Style::Tuple, ref fields) |
None Body::Struct(Style::Newtype, ref fields) => {
Some(deserialize_from_tuple(None, params, fields, &cont.attrs, None))
}
Body::Struct(Style::Unit, _) => None,
} }
} }
+9
View File
@@ -164,6 +164,15 @@ pub enum Identifier {
Variant, Variant,
} }
impl Identifier {
pub fn is_some(self) -> bool {
match self {
Identifier::No => false,
Identifier::Field | Identifier::Variant => true,
}
}
}
impl Container { impl Container {
/// Extract out the `#[serde(...)]` attributes from an item. /// Extract out the `#[serde(...)]` attributes from an item.
pub fn from_ast(cx: &Ctxt, item: &syn::DeriveInput) -> Self { pub fn from_ast(cx: &Ctxt, item: &syn::DeriveInput) -> Self {