fn mk_arm(
    item_ident : &Ident,
    fields : &Fields,
    variant_ident : Option<&Ident>
) -> syn::Arm {
    let (item_path, namestring) : (syn::Path, String)  = match variant_ident {
        // if struct
        None => (
            parse_quote!(#item_ident),
            format!("{}", item_ident)
        ),
        // if enum
        Some(variant) => (
            parse_quote!(#item_ident::#variant),
            format!("{}::{}", item_ident, variant)
        )
    };

    match fields {
        Fields::Named(named) => {
            // the names of fields as idents (iterator).
            let all_idents = named.named.iter().map(|field| field.ident.as_ref().expect(
                "All fields in a Field::Named should have names"
            ));
            let all_idents_copy = all_idents.clone();

            parse_quote! {
                #item_path { #(#all_idents),* } => {
                    let mut base = f.debug_struct(#namestring);
                    #(
                        base.field(
                            stringify!(#all_idents_copy),
                            &format_args!("{:#?}", fe.to(#all_idents_copy))
                        );
                    )*
                    base.finish()
                }
            }
        },
        Fields::Unnamed(unnamed) => {
            let field_idents = unnamed.unnamed.iter().enumerate().map(|(idx, _)| format_ident!("__{}", idx));
            let field_idents_copy = field_idents.clone();

            parse_quote! {
                #item_path (#(#field_idents),*) => {
                    let mut base = f.debug_tuple(#namestring);
                    #(
                        base.field(&format_args!("{:#?}", fe.to(#field_idents_copy)));
                    )*
                    base.finish()
                }
            }
        }
        Fields::Unit => {
            parse_quote! {
                #item_path => {
                    let mut base = f.debug_struct(#namestring);
                    base.finish()
                }
            }
        }
    }
}
// Make a single match arm for either a struct or single enum variant.
// as an example, for the mm0-rs type `Sort`, this function produces:
//
// ```
// Sort { atom, name, span, full, mods } => {
//     let mut base = f.debug_struct("Sort");
//     base.field("atom", format_args!("{:#?}", fe.to(atom))
//     base.field("name", format_args!("{:#?}", fe.to(name))
//     base.field("span", format_args!("{:#?}", fe.to(span))
//     base.field("full", format_args!("{:#?}", fe.to(full))
//     base.field("mods", format_args!("{:#?}", fe.to(mods))
//     base.finish()
// }
// ```
Make a single match arm for either a struct or single enum variant.
as an example, for the mm0-rs type `Sort`, this function produces.


Make a single match arm for either a struct or single enum variant . as an example for the mm0 - rs type ` Sort ` this function produces .
fn mk_arm(
    item_ident : &Ident,
    fields : &Fields,
    variant_ident : Option<&Ident>
) -> syn::Arm {
    let (item_path, namestring) : (syn::Path, String)  = match variant_ident {
        // if struct
        None => (
            parse_quote!(#item_ident),
            format!("{}", item_ident)
        ),
        // if enum
        Some(variant) => (
            parse_quote!(#item_ident::#variant),
            format!("{}::{}", item_ident, variant)
        )
    };
    match fields {
        Fields::Named(named) => {
            // the names of fields as idents (iterator).
            let all_idents = named.named.iter().map(|field| field.ident.as_ref().expect(
                "All fields in a Field::Named should have names"
            ));
            let all_idents_copy = all_idents.clone();
            parse_quote! {
                #item_path { #(#all_idents),* } => {
                    let mut base = f.debug_struct(#namestring);
                    #(
                        base.field(
                            stringify!(#all_idents_copy),
                            &format_args!("{:#?}", fe.to(#all_idents_copy))
                        );
                    )*
                    base.finish()
                }
            }
        },
        Fields::Unnamed(unnamed) => {
            let field_idents = unnamed.unnamed.iter().enumerate().map(|(idx, _)| format_ident!("__{}", idx));
            let field_idents_copy = field_idents.clone();
            parse_quote! {
                #item_path (#(#field_idents),*) => {
                    let mut base = f.debug_tuple(#namestring);
                    #(
                        base.field(&format_args!("{:#?}", fe.to(#field_idents_copy)));
                    )*
                    base.finish()
                }
            }
        }
        Fields::Unit => {
            parse_quote! {
                #item_path => {
                    let mut base = f.debug_struct(#namestring);
                    base.finish()
                }
            }
        }
    }
}
fn mk_arm ( item_ident : & Ident , fields : & Fields , variant_ident : Option < & Ident > ) -> syn :: Arm { let ( item_path , namestring ) : ( syn :: Path , String ) = match variant_ident { // if struct None => ( parse_quote ! ( item_ident ) , format ! ( " " item_ident ) ) , // if enum Some ( variant ) => ( parse_quote ! ( item_ident variant ) , format ! ( " " item_ident variant ) ) } ; match fields { Fields :: Named ( named ) => { // the names of fields as idents (iterator). let all_idents = named . named . iter ( ) . map ( | field | field . ident . as_ref ( ) . expect ( " " ) ) ; let all_idents_copy = all_idents . clone ( ) ; parse_quote ! { item_path { ( all_idents ) } { let mut base f debug_struct ( namestring ) ( base field ( stringify ( all_idents_copy ) format_args ( " " fe to ( all_idents_copy ) ) ) ) base finish ( ) } } } , Fields :: Unnamed ( unnamed ) => { let field_idents = unnamed . unnamed . iter ( ) . enumerate ( ) . map ( | ( idx , _ ) | format_ident ! ( " " idx ) ) ; let field_idents_copy = field_idents . clone ( ) ; parse_quote ! { item_path ( ( field_idents ) ) { let mut base f debug_tuple ( namestring ) ( base field ( format_args ( " " fe to ( field_idents_copy ) ) ) ) base finish ( ) } } } Fields :: Unit => { parse_quote ! { item_path { let mut base f debug_struct ( namestring ) base finish ( ) } } } } }
Make a single match arm for either a struct or single enum variant.
Make a single match arm for either a struct or single enum variant .
item_ident
&Ident
fields
&Fields
variant_ident
Option<&Ident>
item_ident
&Ident
fields
&Fields
variant_ident
Option<&Ident>