fn unwrap_to_variant_closure(
    params: &Parameters,
    variant: &Variant,
    with_wrapper: bool,
) -> TokenStream {
    let this = &params.this;
    let variant_ident = &variant.ident;

    let (arg, wrapper) = if with_wrapper {
        (quote! { __wrap }, quote! { __wrap.value })
    } else {
        let field_tys = variant.fields.iter().map(|field| field.ty);
        (quote! { __wrap: (#(#field_tys),*) }, quote! { __wrap })
    };

    let field_access = (0..variant.fields.len()).map(|n| {
        Member::Unnamed(Index {
            index: n as u32,
            span: Span::call_site(),
        })
    });

    match variant.style {
        Style::Struct if variant.fields.len() == 1 => {
            let member = &variant.fields[0].member;
            quote! {
                |#arg| #this::#variant_ident { #member: #wrapper }
            }
        }
        Style::Struct => {
            let members = variant.fields.iter().map(|field| &field.member);
            quote! {
                |#arg| #this::#variant_ident { #(#members: #wrapper.#field_access),* }
            }
        }
        Style::Tuple => quote! {
            |#arg| #this::#variant_ident(#(#wrapper.#field_access),*)
        },
        Style::Newtype => quote! {
            |#arg| #this::#variant_ident(#wrapper)
        },
        Style::Unit => quote! {
            |#arg| #this::#variant_ident
        },
    }
}
// Generates closure that converts single input parameter to the final value.
Generates closure that converts single input parameter to the final value.
Generates closure that converts single input parameter to the final value .
fn unwrap_to_variant_closure(
    params: &Parameters,
    variant: &Variant,
    with_wrapper: bool,
) -> TokenStream {
    let this = &params.this;
    let variant_ident = &variant.ident;
    let (arg, wrapper) = if with_wrapper {
        (quote! { __wrap }, quote! { __wrap.value })
    } else {
        let field_tys = variant.fields.iter().map(|field| field.ty);
        (quote! { __wrap: (#(#field_tys),*) }, quote! { __wrap })
    };
    let field_access = (0..variant.fields.len()).map(|n| {
        Member::Unnamed(Index {
            index: n as u32,
            span: Span::call_site(),
        })
    });
    match variant.style {
        Style::Struct if variant.fields.len() == 1 => {
            let member = &variant.fields[0].member;
            quote! {
                |#arg| #this::#variant_ident { #member: #wrapper }
            }
        }
        Style::Struct => {
            let members = variant.fields.iter().map(|field| &field.member);
            quote! {
                |#arg| #this::#variant_ident { #(#members: #wrapper.#field_access),* }
            }
        }
        Style::Tuple => quote! {
            |#arg| #this::#variant_ident(#(#wrapper.#field_access),*)
        },
        Style::Newtype => quote! {
            |#arg| #this::#variant_ident(#wrapper)
        },
        Style::Unit => quote! {
            |#arg| #this::#variant_ident
        },
    }
}
fn unwrap_to_variant_closure ( params : & Parameters , variant : & Variant , with_wrapper : bool , ) -> TokenStream { let this = & params . this ; let variant_ident = & variant . ident ; let ( arg , wrapper ) = if with_wrapper { ( quote ! { __wrap } , quote ! { __wrap value } ) } else { let field_tys = variant . fields . iter ( ) . map ( | field | field . ty ) ; ( quote ! { __wrap ( ( field_tys ) ) } , quote ! { __wrap } ) } ; let field_access = ( 0 .. variant . fields . len ( ) ) . map ( | n | { Member :: Unnamed ( Index { index : n as u32 , span : Span :: call_site ( ) , } ) } ) ; match variant . style { Style :: Struct if variant . fields . len ( ) == 1 => { let member = & variant . fields [ 0 ] . member ; quote ! { arg this variant_ident { member wrapper } } } Style :: Struct => { let members = variant . fields . iter ( ) . map ( | field | & field . member ) ; quote ! { arg this variant_ident { ( members wrapper field_access ) } } } Style :: Tuple => quote ! { arg this variant_ident ( ( wrapper field_access ) ) } , Style :: Newtype => quote ! { arg this variant_ident ( wrapper ) } , Style :: Unit => quote ! { arg this variant_ident } , } }
Generates closure that converts single input parameter to the final value.
Generates closure that converts single input parameter to the final value .
params
&Parameters
variant
&Variant
with_wrapper
bool
params
&Parameters
variant
&Variant
with_wrapper
bool