aboutsummaryrefslogtreecommitdiff
path: root/macros/src/injectable/named_attr_input.rs
blob: eaa9dbf6d5bec935d5d1846724a5da8dbfdced64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use quote::ToTokens;
use syn::parse::Parse;
use syn::token::Paren;
use syn::{parenthesized, LitStr};

pub struct NamedAttrInput
{
    pub paren: Paren,
    pub name: LitStr,
}

impl Parse for NamedAttrInput
{
    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self>
    {
        let content;

        let paren = parenthesized!(content in input);

        Ok(Self {
            paren,
            name: content.parse()?,
        })
    }
}

impl ToTokens for NamedAttrInput
{
    fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream)
    {
        self.paren
            .surround(&mut self.name.to_token_stream(), |stream| {
                stream.to_tokens(tokens);
            });
    }
}