pub fn parse(program_mod: &syn::ItemMod) -> ParseResult<(Vec<Ix>, Option<FallbackFn>)> {
    let mod_content = &program_mod
        .content
        .as_ref()
        .ok_or_else(|| ParseError::new(program_mod.span(), "program content not provided"))?
        .1;

    let ixs = mod_content
        .iter()
        .filter_map(|item| match item {
            syn::Item::Fn(item_fn) => {
                let (ctx, _) = parse_args(item_fn).ok()?;
                ctx_accounts_ident(&ctx.raw_arg).ok()?;
                Some(item_fn)
            }
            _ => None,
        })
        .map(|method: &syn::ItemFn| {
            let (ctx, args) = parse_args(method)?;
            let docs = docs::parse(&method.attrs);
            let returns = parse_return(method)?;
            let anchor_ident = ctx_accounts_ident(&ctx.raw_arg)?;
            Ok(Ix {
                raw_method: method.clone(),
                ident: method.sig.ident.clone(),
                docs,
                args,
                anchor_ident,
                returns,
            })
        })
        .collect::<ParseResult<Vec<Ix>>>()?;

    let fallback_fn = {
        let fallback_fns = mod_content
            .iter()
            .filter_map(|item| match item {
                syn::Item::Fn(item_fn) => {
                    let (ctx, _args) = parse_args(item_fn).ok()?;
                    if ctx_accounts_ident(&ctx.raw_arg).is_ok() {
                        return None;
                    }
                    Some(item_fn)
                }
                _ => None,
            })
            .collect::<Vec<_>>();
        if fallback_fns.len() > 1 {
            return Err(ParseError::new(
                fallback_fns[0].span(),
                "More than one fallback function found",
            ));
        }
        fallback_fns
            .first()
            .map(|method: &&syn::ItemFn| FallbackFn {
                raw_method: (*method).clone(),
            })
    };

    Ok((ixs, fallback_fn))
}
// Parse all non-state ix handlers from the program mod definition.
Parse all non-state ix handlers from the program mod definition.
Parse all non - state ix handlers from the program mod definition .
pub fn parse(program_mod: &syn::ItemMod) -> ParseResult<(Vec<Ix>, Option<FallbackFn>)> {
    let mod_content = &program_mod
        .content
        .as_ref()
        .ok_or_else(|| ParseError::new(program_mod.span(), "program content not provided"))?
        .1;
    let ixs = mod_content
        .iter()
        .filter_map(|item| match item {
            syn::Item::Fn(item_fn) => {
                let (ctx, _) = parse_args(item_fn).ok()?;
                ctx_accounts_ident(&ctx.raw_arg).ok()?;
                Some(item_fn)
            }
            _ => None,
        })
        .map(|method: &syn::ItemFn| {
            let (ctx, args) = parse_args(method)?;
            let docs = docs::parse(&method.attrs);
            let returns = parse_return(method)?;
            let anchor_ident = ctx_accounts_ident(&ctx.raw_arg)?;
            Ok(Ix {
                raw_method: method.clone(),
                ident: method.sig.ident.clone(),
                docs,
                args,
                anchor_ident,
                returns,
            })
        })
        .collect::<ParseResult<Vec<Ix>>>()?;
    let fallback_fn = {
        let fallback_fns = mod_content
            .iter()
            .filter_map(|item| match item {
                syn::Item::Fn(item_fn) => {
                    let (ctx, _args) = parse_args(item_fn).ok()?;
                    if ctx_accounts_ident(&ctx.raw_arg).is_ok() {
                        return None;
                    }
                    Some(item_fn)
                }
                _ => None,
            })
            .collect::<Vec<_>>();
        if fallback_fns.len() > 1 {
            return Err(ParseError::new(
                fallback_fns[0].span(),
                "More than one fallback function found",
            ));
        }
        fallback_fns
            .first()
            .map(|method: &&syn::ItemFn| FallbackFn {
                raw_method: (*method).clone(),
            })
    };
    Ok((ixs, fallback_fn))
}
pub fn parse ( program_mod : & syn :: ItemMod ) -> ParseResult < ( Vec < Ix > , Option < FallbackFn > ) > { let mod_content = & program_mod . content . as_ref ( ) . ok_or_else ( | | ParseError :: new ( program_mod . span ( ) , " " ) ) ? . 1 ; let ixs = mod_content . iter ( ) . filter_map ( | item | match item { syn :: Item :: Fn ( item_fn ) => { let ( ctx , _ ) = parse_args ( item_fn ) . ok ( ) ? ; ctx_accounts_ident ( & ctx . raw_arg ) . ok ( ) ? ; Some ( item_fn ) } _ => None , } ) . map ( | method : & syn :: ItemFn | { let ( ctx , args ) = parse_args ( method ) ? ; let docs = docs :: parse ( & method . attrs ) ; let returns = parse_return ( method ) ? ; let anchor_ident = ctx_accounts_ident ( & ctx . raw_arg ) ? ; Ok ( Ix { raw_method : method . clone ( ) , ident : method . sig . ident . clone ( ) , docs , args , anchor_ident , returns , } ) } ) . collect :: < ParseResult < Vec < Ix > > > ( ) ? ; let fallback_fn = { let fallback_fns = mod_content . iter ( ) . filter_map ( | item | match item { syn :: Item :: Fn ( item_fn ) => { let ( ctx , _args ) = parse_args ( item_fn ) . ok ( ) ? ; if ctx_accounts_ident ( & ctx . raw_arg ) . is_ok ( ) { return None ; } Some ( item_fn ) } _ => None , } ) . collect :: < Vec < _ > > ( ) ; if fallback_fns . len ( ) > 1 { return Err ( ParseError :: new ( fallback_fns [ 0 ] . span ( ) , " " , ) ) ; } fallback_fns . first ( ) . map ( | method : & & syn :: ItemFn | FallbackFn { raw_method : ( * method ) . clone ( ) , } ) } ; Ok ( ( ixs , fallback_fn ) ) }
Parse all non-state ix handlers from the program mod definition.
Parse all non - state ix handlers from the program mod definition .
program_mod
&syn::ItemMod