mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-19 22:41:04 +00:00
Less indentiation in deserialize_from_body
This commit is contained in:
+13
-14
@@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user