fn gen_func_list(trait_body: &ItemTrait) -> Vec<Cow<'_, TraitItemMethod>> {
    let ref_receiver: FnArg = parse_quote!(&self); // const

    trait_body
        .items
        .iter()
        .filter_map(|item| match item {
            TraitItem::Method(method) => {
                // check signatures and prepare dummy for bad method

                let mut method = Cow::Borrowed(method);
                if method.default.is_some() {
                    emit_error!(
                        method.default,
                        "trait method can't have default implementation"
                    );

                    // create dummy by remove default and append semicolon(`;`)
                    let mut dummy = method.into_owned();
                    dummy.semi_token = Some(Token![;](dummy.default.span()));
                    dummy.default = None;
                    method = Cow::Owned(dummy);
                }

                if !is_ref_receiver(method.sig.inputs.first()) {
                    emit_error!(method, "trait method must have `&self` receiver");

                    // create dummy by replace bad receiver, append one if none is provided
                    let mut dummy = method.into_owned();
                    match dummy.sig.inputs.first() {
                        Some(FnArg::Receiver(_)) => {
                            // e.g., `&mut self`
                            *(dummy
                                .sig
                                .inputs
                                .first_mut()
                                .expect("infallible: non-mutable use before")) =
                                ref_receiver.clone();
                        }
                        Some(FnArg::Typed(PatType { pat, .. })) => match &**pat {
                            Pat::Ident(PatIdent { ident, .. }) if ident == "self" => {
                                // e.g., `self: Box<Self>`
                                *(dummy
                                    .sig
                                    .inputs
                                    .first_mut()
                                    .expect("infallible: non-mutable use before")) =
                                    ref_receiver.clone();
                            }
                            _ => {
                                // no receiver, just argument
                                dummy.sig.inputs.insert(0, ref_receiver.clone());
                            }
                        },
                        None => {
                            // no receiver and argument
                            dummy.sig.inputs.insert(0, ref_receiver.clone());
                        }
                    }
                    method = Cow::Owned(dummy);
                }

                for i in 0..(method.sig.inputs.len()) {
                    if let FnArg::Typed(PatType { ref pat, .. }) = method.sig.inputs[i] {
                        match pat.as_ref() {
                            Pat::Ident(_) => {}
                            other => {
                                emit_error!(other, "trait method cannot use pattern as argument");

                                let dummy_ident = format_ident!("__dummy_{:x}", {
                                    use std::hash::{Hash, Hasher};

                                    let mut h =
                                        std::collections::hash_map::DefaultHasher::default();
                                    other.hash(&mut h);
                                    h.finish()
                                });

                                let new_pat = Box::new(Pat::Ident(PatIdent {
                                    ident: dummy_ident,
                                    attrs: Default::default(),
                                    by_ref: None,
                                    mutability: None,
                                    subpat: None,
                                }));

                                let mut dummy = method.into_owned();
                                match dummy.sig.inputs[i] {
                                    FnArg::Typed(PatType { ref mut pat, .. }) => *pat = new_pat,
                                    _ => unreachable!(),
                                }
                                method = Cow::Owned(dummy);
                            }
                        }
                    }
                }

                for lifetime in method.sig.generics.lifetimes() {
                    if lifetime.lifetime.ident != "req" {
                        emit_error!(
                            lifetime.lifetime.span(),
                            "trait method may only have one lifetime parameter called `'req`"
                        );
                    }
                }

                Some(method)
            }
            item => {
                emit_error!(
                    item,
                    "#[rpc_define] trait cannot have any item other than function"
                );
                None
            }
        })
        .collect::<Vec<_>>()
}
/// Generate a list of trait method.
///
/// This function emit error and generate dummy for following cases:
///  - A trait method which has a default implementation.
///  - The first input is not `&self` or its equivalent.
///  - An input is given in pattern, e.g., `(x, y): (f32, f32)`.
///  - A trait method which defined at least one lifetime generic parameter except `'req`
Generate a list of trait method.
This function emit error and generate dummy for following cases:
A trait method which has a default implementation.
The first input is not `&self` or its equivalent.
Generate a list of trait method . This function emit error and generate dummy for following cases : A trait method which has a default implementation . The first input is not ` &self ` or its equivalent .
fn gen_func_list(trait_body: &ItemTrait) -> Vec<Cow<'_, TraitItemMethod>> {
    let ref_receiver: FnArg = parse_quote!(&self); // const
    trait_body
        .items
        .iter()
        .filter_map(|item| match item {
            TraitItem::Method(method) => {
                // check signatures and prepare dummy for bad method
                let mut method = Cow::Borrowed(method);
                if method.default.is_some() {
                    emit_error!(
                        method.default,
                        "trait method can't have default implementation"
                    );
                    // create dummy by remove default and append semicolon(`;`)
                    let mut dummy = method.into_owned();
                    dummy.semi_token = Some(Token![;](dummy.default.span()));
                    dummy.default = None;
                    method = Cow::Owned(dummy);
                }
                if !is_ref_receiver(method.sig.inputs.first()) {
                    emit_error!(method, "trait method must have `&self` receiver");
                    // create dummy by replace bad receiver, append one if none is provided
                    let mut dummy = method.into_owned();
                    match dummy.sig.inputs.first() {
                        Some(FnArg::Receiver(_)) => {
                            // e.g., `&mut self`
                            *(dummy
                                .sig
                                .inputs
                                .first_mut()
                                .expect("infallible: non-mutable use before")) =
                                ref_receiver.clone();
                        }
                        Some(FnArg::Typed(PatType { pat, .. })) => match &**pat {
                            Pat::Ident(PatIdent { ident, .. }) if ident == "self" => {
                                // e.g., `self: Box<Self>`
                                *(dummy
                                    .sig
                                    .inputs
                                    .first_mut()
                                    .expect("infallible: non-mutable use before")) =
                                    ref_receiver.clone();
                            }
                            _ => {
                                // no receiver, just argument
                                dummy.sig.inputs.insert(0, ref_receiver.clone());
                            }
                        },
                        None => {
                            // no receiver and argument
                            dummy.sig.inputs.insert(0, ref_receiver.clone());
                        }
                    }
                    method = Cow::Owned(dummy);
                }
                for i in 0..(method.sig.inputs.len()) {
                    if let FnArg::Typed(PatType { ref pat, .. }) = method.sig.inputs[i] {
                        match pat.as_ref() {
                            Pat::Ident(_) => {}
                            other => {
                                emit_error!(other, "trait method cannot use pattern as argument");
                                let dummy_ident = format_ident!("__dummy_{:x}", {
                                    use std::hash::{Hash, Hasher};
                                    let mut h =
                                        std::collections::hash_map::DefaultHasher::default();
                                    other.hash(&mut h);
                                    h.finish()
                                });
                                let new_pat = Box::new(Pat::Ident(PatIdent {
                                    ident: dummy_ident,
                                    attrs: Default::default(),
                                    by_ref: None,
                                    mutability: None,
                                    subpat: None,
                                }));
                                let mut dummy = method.into_owned();
                                match dummy.sig.inputs[i] {
                                    FnArg::Typed(PatType { ref mut pat, .. }) => *pat = new_pat,
                                    _ => unreachable!(),
                                }
                                method = Cow::Owned(dummy);
                            }
                        }
                    }
                }
                for lifetime in method.sig.generics.lifetimes() {
                    if lifetime.lifetime.ident != "req" {
                        emit_error!(
                            lifetime.lifetime.span(),
                            "trait method may only have one lifetime parameter called `'req`"
                        );
                    }
                }
                Some(method)
            }
            item => {
                emit_error!(
                    item,
                    "#[rpc_define] trait cannot have any item other than function"
                );
                None
            }
        })
        .collect::<Vec<_>>()
}
fn gen_func_list ( trait_body : & ItemTrait ) -> Vec < Cow < ' _ , TraitItemMethod > > { let ref_receiver : FnArg = parse_quote ! ( self ) ; // const trait_body . items . iter ( ) . filter_map ( | item | match item { TraitItem :: Method ( method ) => { // check signatures and prepare dummy for bad method let mut method = Cow :: Borrowed ( method ) ; if method . default . is_some ( ) { emit_error ! ( method default " " ) ; // create dummy by remove default and append semicolon(`;`) let mut dummy = method . into_owned ( ) ; dummy . semi_token = Some ( Token ! [ ] ( dummy . default . span ( ) ) ) ; dummy . default = None ; method = Cow :: Owned ( dummy ) ; } if ! is_ref_receiver ( method . sig . inputs . first ( ) ) { emit_error ! ( method " " ) ; // create dummy by replace bad receiver, append one if none is provided let mut dummy = method . into_owned ( ) ; match dummy . sig . inputs . first ( ) { Some ( FnArg :: Receiver ( _ ) ) => { // e.g., `&mut self` * ( dummy . sig . inputs . first_mut ( ) . expect ( " " ) ) = ref_receiver . clone ( ) ; } Some ( FnArg :: Typed ( PatType { pat , .. } ) ) => match & * * pat { Pat :: Ident ( PatIdent { ident , .. } ) if ident == " " => { // e.g., `self: Box<Self>` * ( dummy . sig . inputs . first_mut ( ) . expect ( " " ) ) = ref_receiver . clone ( ) ; } _ => { // no receiver, just argument dummy . sig . inputs . insert ( 0 , ref_receiver . clone ( ) ) ; } } , None => { // no receiver and argument dummy . sig . inputs . insert ( 0 , ref_receiver . clone ( ) ) ; } } method = Cow :: Owned ( dummy ) ; } for i in 0 .. ( method . sig . inputs . len ( ) ) { if let FnArg :: Typed ( PatType { ref pat , .. } ) = method . sig . inputs [ i ] { match pat . as_ref ( ) { Pat :: Ident ( _ ) => { } other => { emit_error ! ( other " " ) ; let dummy_ident = format_ident ! ( " " { use std hash { Hash Hasher } let mut h std collections hash_map DefaultHasher default ( ) other hash ( mut h ) h finish ( ) } ) ; let new_pat = Box :: new ( Pat :: Ident ( PatIdent { ident : dummy_ident , attrs : Default :: default ( ) , by_ref : None , mutability : None , subpat : None , } ) ) ; let mut dummy = method . into_owned ( ) ; match dummy . sig . inputs [ i ] { FnArg :: Typed ( PatType { ref mut pat , .. } ) => * pat = new_pat , _ => unreachable ! ( ) , } method = Cow :: Owned ( dummy ) ; } } } } for lifetime in method . sig . generics . lifetimes ( ) { if lifetime . lifetime . ident != " " { emit_error ! ( lifetime lifetime span ( ) " " ) ; } } Some ( method ) } item => { emit_error ! ( item " " ) ; None } } ) . collect :: < Vec < _ > > ( ) }
Generate a list of trait method.
Generate a list of trait method .
trait_body
&ItemTrait
trait_body
&ItemTrait