pub fn maybe_path_prefix(&self) -> Option<(ast::Path, &TokenSlice)> {
        let mut segments: Vec<ast::PathSegment> = Vec::new();

        let path: Vec<&TokenTree> = self.iter()
            .take_while(|x| x.is_ident() || x.eq_token(Token::ModSep))
            .collect::<Vec<&TokenTree>>();

        let path_size = path.len();
        if path_size == 0 {
            return None;
        }

        let cov_span = self[..path_size].covering_span();
        let rst = &self[path_size..];

        let fst_id = path[0];

        if let Some(id) = fst_id.maybe_ident() {
            segments.push(ast::PathSegment {
                identifier: id,
                parameters: ast::PathParameters::none(),
            });
        } else {
            return None;
        }

        // Let's use a state machine to parse out the rest.
        enum State {
            Mod, // Expect a `::`, or return None otherwise.
            Ident, // Expect an ident, or return None otherwise.
        }
        let mut state = State::Mod;

        for p in &path[1..] {
            match state {
                State::Mod => {
                    // State 0: ['::' -> state 1, else return None]
                    if p.eq_token(Token::ModSep) {
                        state = State::Ident;
                    } else {
                        return None;
                    }
                }
                State::Ident => {
                    // State 1: [ident -> state 0, else return None]
                    if let Some(id) = p.maybe_ident() {
                        segments.push(ast::PathSegment {
                            identifier: id,
                            parameters: ast::PathParameters::none(),
                        });
                        state = State::Mod;
                    } else {
                        return None;
                    }
                }
            }
        }

        let path = ast::Path {
            span: cov_span,
            global: false,
            segments: segments,
        };
        Some((path, rst))
    }
/// This operation extracts the path prefix , returning an AST path struct and the remainder
/// of the stream (if it finds one). To be more specific, a tokenstream that has a valid,
/// non-global path as a prefix (eg `foo(bar, baz)`, `foo::bar(bar)`, but *not*
/// `::foo::bar(baz)`) will yield the path and the remaining tokens (as a slice). The previous
/// examples will yield
/// `Some((Path { segments = vec![foo], ... }, [(bar, baz)]))`,
/// `Some((Path { segments = vec![foo, bar] }, [(baz)]))`,
/// and `None`, respectively.
This operation extracts the path prefix , returning an AST path struct and the remainder
of the stream (if it finds one).
This operation extracts the path prefix returning an AST path struct and the remainder of the stream ( if it finds one ) .
pub fn maybe_path_prefix(&self) -> Option<(ast::Path, &TokenSlice)> {
        let mut segments: Vec<ast::PathSegment> = Vec::new();
        let path: Vec<&TokenTree> = self.iter()
            .take_while(|x| x.is_ident() || x.eq_token(Token::ModSep))
            .collect::<Vec<&TokenTree>>();
        let path_size = path.len();
        if path_size == 0 {
            return None;
        }
        let cov_span = self[..path_size].covering_span();
        let rst = &self[path_size..];
        let fst_id = path[0];
        if let Some(id) = fst_id.maybe_ident() {
            segments.push(ast::PathSegment {
                identifier: id,
                parameters: ast::PathParameters::none(),
            });
        } else {
            return None;
        }
        // Let's use a state machine to parse out the rest.
        enum State {
            Mod, // Expect a `::`, or return None otherwise.
            Ident, // Expect an ident, or return None otherwise.
        }
        let mut state = State::Mod;
        for p in &path[1..] {
            match state {
                State::Mod => {
                    // State 0: ['::' -> state 1, else return None]
                    if p.eq_token(Token::ModSep) {
                        state = State::Ident;
                    } else {
                        return None;
                    }
                }
                State::Ident => {
                    // State 1: [ident -> state 0, else return None]
                    if let Some(id) = p.maybe_ident() {
                        segments.push(ast::PathSegment {
                            identifier: id,
                            parameters: ast::PathParameters::none(),
                        });
                        state = State::Mod;
                    } else {
                        return None;
                    }
                }
            }
        }
        let path = ast::Path {
            span: cov_span,
            global: false,
            segments: segments,
        };
        Some((path, rst))
    }
pub fn maybe_path_prefix ( & self ) -> Option < ( ast :: Path , & TokenSlice ) > { let mut segments : Vec < ast :: PathSegment > = Vec :: new ( ) ; let path : Vec < & TokenTree > = self . iter ( ) . take_while ( | x | x . is_ident ( ) || x . eq_token ( Token :: ModSep ) ) . collect :: < Vec < & TokenTree > > ( ) ; let path_size = path . len ( ) ; if path_size == 0 { return None ; } let cov_span = self [ .. path_size ] . covering_span ( ) ; let rst = & self [ path_size .. ] ; let fst_id = path [ 0 ] ; if let Some ( id ) = fst_id . maybe_ident ( ) { segments . push ( ast :: PathSegment { identifier : id , parameters : ast :: PathParameters :: none ( ) , } ) ; } else { return None ; } // Let's use a state machine to parse out the rest. enum State { Mod , // Expect a `::`, or return None otherwise. Ident , // Expect an ident, or return None otherwise. } let mut state = State :: Mod ; for p in & path [ 1 .. ] { match state { State :: Mod => { // State 0: ['::' -> state 1, else return None] if p . eq_token ( Token :: ModSep ) { state = State :: Ident ; } else { return None ; } } State :: Ident => { // State 1: [ident -> state 0, else return None] if let Some ( id ) = p . maybe_ident ( ) { segments . push ( ast :: PathSegment { identifier : id , parameters : ast :: PathParameters :: none ( ) , } ) ; state = State :: Mod ; } else { return None ; } } } } let path = ast :: Path { span : cov_span , global : false , segments : segments , } ; Some ( ( path , rst ) ) }
This operation extracts the path prefix , returning an AST path struct and the remainder
of the stream (if it finds one).
This operation extracts the path prefix returning an AST path struct and the remainder of the stream ( if it finds one ) .
&self
&self