macro_rules! parenthesized {
($content:ident in $cursor:expr) => { ... };
}
Available on crate feature
parsing
only.Expand description
Parse a set of parentheses and expose their content to subsequent parsers.
ยงExample
use syn::{parenthesized, token, Ident, Result, Token, Type};
use syn::parse::{Parse, ParseStream};
use syn::punctuated::Punctuated;
// Parse a simplified tuple struct syntax like:
//
// struct S(A, B);
struct TupleStruct {
struct_token: Token![struct],
ident: Ident,
paren_token: token::Paren,
fields: Punctuated<Type, Token![,]>,
semi_token: Token![;],
}
impl Parse for TupleStruct {
fn parse(input: ParseStream) -> Result<Self> {
let content;
Ok(TupleStruct {
struct_token: input.parse()?,
ident: input.parse()?,
paren_token: parenthesized!(content in input),
fields: content.parse_terminated(Type::parse, Token![,])?,
semi_token: input.parse()?,
})
}
}