fn try_parse_expansion(
        &self,
        punct: &p::Punct,
        output: &mut Builder,
        it: &mut Peekable<impl Iterator<Item = TokenTree> + Clone>,
    ) -> Result<bool, Error> {
        // Clone for lookahead.
        let mut lh = it.clone();

        let next = match lh.next() {
            Some(next) => next,
            None => return Ok(false),
        };

        match next {
            // `#value` expansion.
            TokenTree::Ident(ident) => {
                self.encode_to_tokens(punct.span(), output, ident);
            }
            // `#(<expr>)<sep>*` repetition.
            TokenTree::Group(group) if group.delimiter() == p::Delimiter::Parenthesis => {
                let group = group.stream();

                // Parse the repitition character.
                let sep = match (lh.next(), lh.next()) {
                    (Some(sep), Some(TokenTree::Punct(p))) if p.as_char() == '*' => sep,
                    _ => return Ok(false),
                };

                output.push((
                    ("let", "mut", "it"),
                    '=',
                    ("IntoIterator", S, "into_iter", p(('&', group))),
                    ('.', "peekable", p(())),
                    ';',
                ));

                let body = (
                    (
                        ToTokensFn,
                        p(('&', "value", ',', self.ctx, ',', self.stream)),
                        ';',
                    ),
                    ("if", "it", '.', "peek", p(()), '.', "is_some", p(())),
                    braced(self.process(TokenStream::from(sep))?),
                );

                output.push((
                    ("while", "let", "Some", p("value")),
                    '=',
                    ("it", '.', "next", p(()), braced(body)),
                ));

                it.next();
                it.next();
                it.next();
                return Ok(true);
            }
            // Non-expansions.
            _ => return Ok(false),
        }

        it.next();
        Ok(true)
    }
/// Try to parse an expansion.
Try to parse an expansion.
Try to parse an expansion .
fn try_parse_expansion(
        &self,
        punct: &p::Punct,
        output: &mut Builder,
        it: &mut Peekable<impl Iterator<Item = TokenTree> + Clone>,
    ) -> Result<bool, Error> {
        // Clone for lookahead.
        let mut lh = it.clone();
        let next = match lh.next() {
            Some(next) => next,
            None => return Ok(false),
        };
        match next {
            // `#value` expansion.
            TokenTree::Ident(ident) => {
                self.encode_to_tokens(punct.span(), output, ident);
            }
            // `#(<expr>)<sep>*` repetition.
            TokenTree::Group(group) if group.delimiter() == p::Delimiter::Parenthesis => {
                let group = group.stream();
                // Parse the repitition character.
                let sep = match (lh.next(), lh.next()) {
                    (Some(sep), Some(TokenTree::Punct(p))) if p.as_char() == '*' => sep,
                    _ => return Ok(false),
                };
                output.push((
                    ("let", "mut", "it"),
                    '=',
                    ("IntoIterator", S, "into_iter", p(('&', group))),
                    ('.', "peekable", p(())),
                    ';',
                ));
                let body = (
                    (
                        ToTokensFn,
                        p(('&', "value", ',', self.ctx, ',', self.stream)),
                        ';',
                    ),
                    ("if", "it", '.', "peek", p(()), '.', "is_some", p(())),
                    braced(self.process(TokenStream::from(sep))?),
                );
                output.push((
                    ("while", "let", "Some", p("value")),
                    '=',
                    ("it", '.', "next", p(()), braced(body)),
                ));
                it.next();
                it.next();
                it.next();
                return Ok(true);
            }
            // Non-expansions.
            _ => return Ok(false),
        }
        it.next();
        Ok(true)
    }
fn try_parse_expansion ( & self , punct : & p :: Punct , output : & mut Builder , it : & mut Peekable < impl Iterator < Item = TokenTree > + Clone > , ) -> Result < bool , Error > { // Clone for lookahead. let mut lh = it . clone ( ) ; let next = match lh . next ( ) { Some ( next ) => next , None => return Ok ( false ) , } ; match next { // `#value` expansion. TokenTree :: Ident ( ident ) => { self . encode_to_tokens ( punct . span ( ) , output , ident ) ; } // `#(<expr>)<sep>*` repetition. TokenTree :: Group ( group ) if group . delimiter ( ) == p :: Delimiter :: Parenthesis => { let group = group . stream ( ) ; // Parse the repitition character. let sep = match ( lh . next ( ) , lh . next ( ) ) { ( Some ( sep ) , Some ( TokenTree :: Punct ( p ) ) ) if p . as_char ( ) == '*' => sep , _ => return Ok ( false ) , } ; output . push ( ( ( " " , " " , " " ) , '=' , ( " " , S , " " , p ( ( '&' , group ) ) ) , ( '.' , " " , p ( ( ) ) ) , ';' , ) ) ; let body = ( ( ToTokensFn , p ( ( '&' , " " , ',' , self . ctx , ',' , self . stream ) ) , ';' , ) , ( " " , " " , '.' , " " , p ( ( ) ) , '.' , " " , p ( ( ) ) ) , braced ( self . process ( TokenStream :: from ( sep ) ) ? ) , ) ; output . push ( ( ( " " , " " , " " , p ( " " ) ) , '=' , ( " " , '.' , " " , p ( ( ) ) , braced ( body ) ) , ) ) ; it . next ( ) ; it . next ( ) ; it . next ( ) ; return Ok ( true ) ; } // Non-expansions. _ => return Ok ( false ) , } it . next ( ) ; Ok ( true ) }
Try to parse an expansion.
Try to parse an expansion .
&self
punct
&p::Punct
output
&mut Builder
it
&mut Peekable<impl Iterator<Item = TokenTree> + Clone>
&self
punct
&p::Punct
output
&mut Builder
it
&mut Peekable<impl Iterator<Item = TokenTree> + Clone>