Macro syn::bracketed[][src]

macro_rules! bracketed {
    ($content:ident in $cursor:expr) => { ... };
}

Parse a set of square brackets and expose their content to subsequent parsers.

Example

#[macro_use]
extern crate syn;

extern crate proc_macro2;

use proc_macro2::TokenStream;
use syn::token;
use syn::parse::{Parse, ParseStream, Result};

// 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()?,
        })
    }
}