[−][src]Macro syn::bracketed
Parse a set of square brackets and expose their content to subsequent parsers.
Example
# use quote::quote;
#
use proc_macro2::TokenStream;
use syn::{bracketed, token, Result, Token};
use syn::parse::{Parse, ParseStream};
// Parse an outer attribute like:
//
// #[repr(C, packed)]
struct OuterAttribute {
pound_token: Token![#],
bracket_token: token::Bracket,
content: TokenStream,
}
impl Parse for OuterAttribute {
fn parse(input: ParseStream) -> Result<Self> {
let content;
Ok(OuterAttribute {
pound_token: input.parse()?,
bracket_token: bracketed!(content in input),
content: content.parse()?,
})
}
}
#
# fn main() {
# let input = quote! {
# #[repr(C, packed)]
# };
# syn::parse2::<OuterAttribute>(input).unwrap();
# }