fn deserialize_internally_tagged_variant(
    params: &Parameters,
    variant: &Variant,
    cattrs: &attr::Container,
    deserializer: TokenStream,
) -> Fragment {
    if variant.attrs.deserialize_with().is_some() {
        return deserialize_untagged_variant(params, variant, cattrs, deserializer);
    }

    let variant_ident = &variant.ident;

    match effective_style(variant) {
        Style::Unit => {
            let this = &params.this;
            let type_name = params.type_name();
            let variant_name = variant.ident.to_string();
            let default = variant.fields.get(0).map(|field| {
                let default = Expr(expr_is_missing(field, cattrs));
                quote!((#default))
            });
            quote_block! {
                try!(_serde::Deserializer::deserialize_any(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name)));
                _serde::__private::Ok(#this::#variant_ident #default)
            }
        }
        Style::Newtype => deserialize_untagged_newtype_variant(
            variant_ident,
            params,
            &variant.fields[0],
            &deserializer,
        ),
        Style::Struct => deserialize_struct(
            Some(variant_ident),
            params,
            &variant.fields,
            cattrs,
            Some(deserializer),
            &Untagged::No,
        ),
        Style::Tuple => unreachable!("checked in serde_derive_internals"),
    }
}
// Generates significant part of the visit_seq and visit_map bodies of visitors
// for the variants of internally tagged enum.
Generates significant part of the visit_seq and visit_map bodies of visitors
for the variants of internally tagged enum.
Generates significant part of the visit_seq and visit_map bodies of visitors for the variants of internally tagged enum .
fn deserialize_internally_tagged_variant(
    params: &Parameters,
    variant: &Variant,
    cattrs: &attr::Container,
    deserializer: TokenStream,
) -> Fragment {
    if variant.attrs.deserialize_with().is_some() {
        return deserialize_untagged_variant(params, variant, cattrs, deserializer);
    }
    let variant_ident = &variant.ident;
    match effective_style(variant) {
        Style::Unit => {
            let this = &params.this;
            let type_name = params.type_name();
            let variant_name = variant.ident.to_string();
            let default = variant.fields.get(0).map(|field| {
                let default = Expr(expr_is_missing(field, cattrs));
                quote!((#default))
            });
            quote_block! {
                try!(_serde::Deserializer::deserialize_any(#deserializer, _serde::__private::de::InternallyTaggedUnitVisitor::new(#type_name, #variant_name)));
                _serde::__private::Ok(#this::#variant_ident #default)
            }
        }
        Style::Newtype => deserialize_untagged_newtype_variant(
            variant_ident,
            params,
            &variant.fields[0],
            &deserializer,
        ),
        Style::Struct => deserialize_struct(
            Some(variant_ident),
            params,
            &variant.fields,
            cattrs,
            Some(deserializer),
            &Untagged::No,
        ),
        Style::Tuple => unreachable!("checked in serde_derive_internals"),
    }
}
fn deserialize_internally_tagged_variant ( params : & Parameters , variant : & Variant , cattrs : & attr :: Container , deserializer : TokenStream , ) -> Fragment { if variant . attrs . deserialize_with ( ) . is_some ( ) { return deserialize_untagged_variant ( params , variant , cattrs , deserializer ) ; } let variant_ident = & variant . ident ; match effective_style ( variant ) { Style :: Unit => { let this = & params . this ; let type_name = params . type_name ( ) ; let variant_name = variant . ident . to_string ( ) ; let default = variant . fields . get ( 0 ) . map ( | field | { let default = Expr ( expr_is_missing ( field , cattrs ) ) ; quote ! ( ( default ) ) } ) ; quote_block ! { try ( _serde Deserializer deserialize_any ( deserializer _serde private de InternallyTaggedUnitVisitor new ( type_name variant_name ) ) ) _serde private Ok ( this variant_ident default ) } } Style :: Newtype => deserialize_untagged_newtype_variant ( variant_ident , params , & variant . fields [ 0 ] , & deserializer , ) , Style :: Struct => deserialize_struct ( Some ( variant_ident ) , params , & variant . fields , cattrs , Some ( deserializer ) , & Untagged :: No , ) , Style :: Tuple => unreachable ! ( " " ) , } }
Generates significant part of the visit_seq and visit_map bodies of visitors
for the variants of internally tagged enum.
Generates significant part of the visit_seq and visit_map bodies of visitors for the variants of internally tagged enum .
params
&Parameters
variant
&Variant
cattrs
&attr::Container
deserializer
TokenStream
params
&Parameters
variant
&Variant
cattrs
&attr::Container
deserializer
TokenStream