/// Parse an Item attaching the given meta and optional path.
Parse an Item attaching the given meta and optional path.
Parse an Item attaching the given meta and optional path .
pub fn parse_with_meta_path(
        p: &mut Parser<'_>,
        mut attributes: Vec<ast::Attribute>,
        mut visibility: ast::Visibility,
        path: Option<ast::Path>,
    ) -> Result<Self, ParseError> {
        use std::mem::take;
        let item = if let Some(path) = path {
            Self::MacroCall(Box::new(ast::MacroCall::parse_with_meta_path(
                p,
                take(&mut attributes),
                path,
            )?))
        } else {
            let mut const_token = p.parse::<Option<T![const]>>()?;
            let mut async_token = p.parse::<Option<T![async]>>()?;
            let item = match p.nth(0)? {
                K![use] => Self::Use(Box::new(ast::ItemUse::parse_with_meta(
                    p,
                    take(&mut attributes),
                    take(&mut visibility),
                )?)),
                K![enum] => Self::Enum(Box::new(ast::ItemEnum::parse_with_meta(
                    p,
                    take(&mut attributes),
                    take(&mut visibility),
                )?)),
                K![struct] => Self::Struct(Box::new(ast::ItemStruct::parse_with_meta(
                    p,
                    take(&mut attributes),
                    take(&mut visibility),
                )?)),
                K![impl] => Self::Impl(Box::new(ast::ItemImpl::parse_with_attributes(
                    p,
                    take(&mut attributes),
                )?)),
                K![fn] => Self::Fn(Box::new(ast::ItemFn::parse_with_meta(
                    p,
                    take(&mut attributes),
                    take(&mut visibility),
                    take(&mut const_token),
                    take(&mut async_token),
                )?)),
                K![mod] => Self::Mod(Box::new(ast::ItemMod::parse_with_meta(
                    p,
                    take(&mut attributes),
                    take(&mut visibility),
                )?)),
                K![ident] => {
                    if let Some(const_token) = const_token.take() {
                        Self::Const(Box::new(ast::ItemConst::parse_with_meta(
                            p,
                            take(&mut attributes),
                            take(&mut visibility),
                            const_token,
                        )?))
                    } else {
                        Self::MacroCall(p.parse()?)
                    }
                }
                _ => {
                    return Err(ParseError::expected(
                        &p.tok_at(0)?,
                        "`fn`, `mod`, `struct`, `enum`, `use`, or macro call",
                    ))
                }
            };
            if let Some(span) = const_token.option_span() {
                return Err(ParseError::unsupported(span, "const modifier"));
            }
            if let Some(span) = async_token.option_span() {
                return Err(ParseError::unsupported(span, "async modifier"));
            }
            item
        };
        if let Some(span) = attributes.option_span() {
            return Err(ParseError::unsupported(span, "attribute"));
        }
        if let Some(span) = visibility.option_span() {
            return Err(ParseError::unsupported(span, "visibility modifier"));
        }
        Ok(item)
    }
pub fn parse_with_meta_path ( p : & mut Parser < ' _ > , mut attributes : Vec < ast :: Attribute > , mut visibility : ast :: Visibility , path : Option < ast :: Path > , ) -> Result < Self , ParseError > { use std :: mem :: take ; let item = if let Some ( path ) = path { Self :: MacroCall ( Box :: new ( ast :: MacroCall :: parse_with_meta_path ( p , take ( & mut attributes ) , path , ) ? ) ) } else { let mut const_token = p . parse :: < Option < T ! [ const ] > > ( ) ? ; let mut async_token = p . parse :: < Option < T ! [ async ] > > ( ) ? ; let item = match p . nth ( 0 ) ? { K ! [ use ] => Self :: Use ( Box :: new ( ast :: ItemUse :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , ) ? ) ) , K ! [ enum ] => Self :: Enum ( Box :: new ( ast :: ItemEnum :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , ) ? ) ) , K ! [ struct ] => Self :: Struct ( Box :: new ( ast :: ItemStruct :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , ) ? ) ) , K ! [ impl ] => Self :: Impl ( Box :: new ( ast :: ItemImpl :: parse_with_attributes ( p , take ( & mut attributes ) , ) ? ) ) , K ! [ fn ] => Self :: Fn ( Box :: new ( ast :: ItemFn :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , take ( & mut const_token ) , take ( & mut async_token ) , ) ? ) ) , K ! [ mod ] => Self :: Mod ( Box :: new ( ast :: ItemMod :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , ) ? ) ) , K ! [ ident ] => { if let Some ( const_token ) = const_token . take ( ) { Self :: Const ( Box :: new ( ast :: ItemConst :: parse_with_meta ( p , take ( & mut attributes ) , take ( & mut visibility ) , const_token , ) ? ) ) } else { Self :: MacroCall ( p . parse ( ) ? ) } } _ => { return Err ( ParseError :: expected ( & p . tok_at ( 0 ) ? , " " , ) ) } } ; if let Some ( span ) = const_token . option_span ( ) { return Err ( ParseError :: unsupported ( span , " " ) ) ; } if let Some ( span ) = async_token . option_span ( ) { return Err ( ParseError :: unsupported ( span , " " ) ) ; } item } ; if let Some ( span ) = attributes . option_span ( ) { return Err ( ParseError :: unsupported ( span , " " ) ) ; } if let Some ( span ) = visibility . option_span ( ) { return Err ( ParseError :: unsupported ( span , " " ) ) ; } Ok ( item ) }
Parse an Item attaching the given meta and optional path.
Parse an Item attaching the given meta and optional path .
p
&mut Parser<'_>
attributes
Vec<ast::Attribute>
visibility
ast::Visibility
path
Option<ast::Path>