pub fn push_method(&mut self, item: TraitItemMethod) -> Result<()> {
        let self_ty = SelfType::parse(item.sig.inputs.iter().next())?;
        let mut args = Vec::with_capacity(item.sig.inputs.len());
        item.sig.inputs.iter().skip(1).try_for_each(|arg| match arg {
            FnArg::Typed(arg) => {
                args.push(&arg.pat);
                Ok(())
            }
            _ => error!(arg, "unsupported arguments type"),
        })?;
        let args = &args;

        let method = &item.sig.ident;
        let ident = &self.data.ident;
        let method = match self_ty {
            SelfType::None => {
                let trait_ = self.trait_path();
                let arms = if trait_.is_none() {
                    self.arms(|v| quote!(#ident::#v(x) => x.#method(#(#args),*)))
                } else {
                    self.arms(|v| quote!(#ident::#v(x) => #trait_::#method(x #(,#args)*)))
                };
                parse_quote!(match self { #arms })
            }

            SelfType::Pin(mode, pin) => {
                self.unsafe_code = true;
                let trait_ = self.trait_path();
                let arms = if trait_.is_none() {
                    self.arms(
                        |v| quote!(#ident::#v(x) => #pin::new_unchecked(x).#method(#(#args),*)),
                    )
                } else {
                    self.arms(|v| quote!(#ident::#v(x) => #trait_::#method(#pin::new_unchecked(x) #(,#args)*)))
                };

                match mode {
                    CaptureMode::Ref { mutability: false } => {
                        if self.unsafety || item.sig.unsafety.is_some() {
                            parse_quote!(match #pin::get_ref(self) { #arms })
                        } else {
                            parse_quote!(unsafe { match #pin::get_ref(self) { #arms } })
                        }
                    }
                    CaptureMode::Ref { mutability: true } => {
                        if self.unsafety || item.sig.unsafety.is_some() {
                            parse_quote!(match #pin::get_unchecked_mut(self) { #arms })
                        } else {
                            parse_quote!(unsafe { match #pin::get_unchecked_mut(self) { #arms } })
                        }
                    }
                }
            }
        };

        method.map(|method| {
            self.push_item(ImplItem::Method(ImplItemMethod {
                attrs: item.attrs,
                vis: Visibility::Inherited,
                defaultness: None,
                sig: item.sig,
                block: Block {
                    brace_token: token::Brace::default(),
                    stmts: vec![Stmt::Expr(method)],
                },
            }))
        })
    }
/// Appends a method from `TraitItemMethod` to impl items.
///
/// A method that has the first argument other than the following is error:
/// - `&self`
/// - `&mut self`
/// - `self`
/// - `mut self`
/// - `self: Pin<&Self>`
/// - `self: Pin<&mut Self>`
Appends a method from `TraitItemMethod` to impl items.
Appends a method from ` TraitItemMethod ` to impl items .
pub fn push_method(&mut self, item: TraitItemMethod) -> Result<()> {
        let self_ty = SelfType::parse(item.sig.inputs.iter().next())?;
        let mut args = Vec::with_capacity(item.sig.inputs.len());
        item.sig.inputs.iter().skip(1).try_for_each(|arg| match arg {
            FnArg::Typed(arg) => {
                args.push(&arg.pat);
                Ok(())
            }
            _ => error!(arg, "unsupported arguments type"),
        })?;
        let args = &args;
        let method = &item.sig.ident;
        let ident = &self.data.ident;
        let method = match self_ty {
            SelfType::None => {
                let trait_ = self.trait_path();
                let arms = if trait_.is_none() {
                    self.arms(|v| quote!(#ident::#v(x) => x.#method(#(#args),*)))
                } else {
                    self.arms(|v| quote!(#ident::#v(x) => #trait_::#method(x #(,#args)*)))
                };
                parse_quote!(match self { #arms })
            }
            SelfType::Pin(mode, pin) => {
                self.unsafe_code = true;
                let trait_ = self.trait_path();
                let arms = if trait_.is_none() {
                    self.arms(
                        |v| quote!(#ident::#v(x) => #pin::new_unchecked(x).#method(#(#args),*)),
                    )
                } else {
                    self.arms(|v| quote!(#ident::#v(x) => #trait_::#method(#pin::new_unchecked(x) #(,#args)*)))
                };
                match mode {
                    CaptureMode::Ref { mutability: false } => {
                        if self.unsafety || item.sig.unsafety.is_some() {
                            parse_quote!(match #pin::get_ref(self) { #arms })
                        } else {
                            parse_quote!(unsafe { match #pin::get_ref(self) { #arms } })
                        }
                    }
                    CaptureMode::Ref { mutability: true } => {
                        if self.unsafety || item.sig.unsafety.is_some() {
                            parse_quote!(match #pin::get_unchecked_mut(self) { #arms })
                        } else {
                            parse_quote!(unsafe { match #pin::get_unchecked_mut(self) { #arms } })
                        }
                    }
                }
            }
        };
        method.map(|method| {
            self.push_item(ImplItem::Method(ImplItemMethod {
                attrs: item.attrs,
                vis: Visibility::Inherited,
                defaultness: None,
                sig: item.sig,
                block: Block {
                    brace_token: token::Brace::default(),
                    stmts: vec![Stmt::Expr(method)],
                },
            }))
        })
    }
pub fn push_method ( & mut self , item : TraitItemMethod ) -> Result < ( ) > { let self_ty = SelfType :: parse ( item . sig . inputs . iter ( ) . next ( ) ) ? ; let mut args = Vec :: with_capacity ( item . sig . inputs . len ( ) ) ; item . sig . inputs . iter ( ) . skip ( 1 ) . try_for_each ( | arg | match arg { FnArg :: Typed ( arg ) => { args . push ( & arg . pat ) ; Ok ( ( ) ) } _ => error ! ( arg " " ) , } ) ? ; let args = & args ; let method = & item . sig . ident ; let ident = & self . data . ident ; let method = match self_ty { SelfType :: None => { let trait_ = self . trait_path ( ) ; let arms = if trait_ . is_none ( ) { self . arms ( | v | quote ! ( ident v ( x ) x method ( ( args ) ) ) ) } else { self . arms ( | v | quote ! ( ident v ( x ) trait_ method ( x ( args ) ) ) ) } ; parse_quote ! ( match self { arms } ) } SelfType :: Pin ( mode , pin ) => { self . unsafe_code = true ; let trait_ = self . trait_path ( ) ; let arms = if trait_ . is_none ( ) { self . arms ( | v | quote ! ( ident v ( x ) pin new_unchecked ( x ) method ( ( args ) ) ) , ) } else { self . arms ( | v | quote ! ( ident v ( x ) trait_ method ( pin new_unchecked ( x ) ( args ) ) ) ) } ; match mode { CaptureMode :: Ref { mutability : false } => { if self . unsafety || item . sig . unsafety . is_some ( ) { parse_quote ! ( match pin get_ref ( self ) { arms } ) } else { parse_quote ! ( unsafe { match pin get_ref ( self ) { arms } } ) } } CaptureMode :: Ref { mutability : true } => { if self . unsafety || item . sig . unsafety . is_some ( ) { parse_quote ! ( match pin get_unchecked_mut ( self ) { arms } ) } else { parse_quote ! ( unsafe { match pin get_unchecked_mut ( self ) { arms } } ) } } } } } ; method . map ( | method | { self . push_item ( ImplItem :: Method ( ImplItemMethod { attrs : item . attrs , vis : Visibility :: Inherited , defaultness : None , sig : item . sig , block : Block { brace_token : token :: Brace :: default ( ) , stmts : vec ! [ Stmt Expr ( method ) ] , } , } ) ) } ) }
Appends a method from `TraitItemMethod` to impl items.
Appends a method from ` TraitItemMethod ` to impl items .
&mut self
item
TraitItemMethod
&mut self
item
TraitItemMethod