File: args.rs

package info (click to toggle)
rust-serde-json-path-macros-internal 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144 kB
  • sloc: makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download
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
use syn::{parse::Parse, LitStr};

use crate::common::args::StrArg;

#[derive(Default)]
pub(crate) struct FunctionMacroArgs {
    pub(crate) name: Option<LitStr>,
}

impl Parse for FunctionMacroArgs {
    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
        let mut args = Self::default();
        while !input.is_empty() {
            let lookahead = input.lookahead1();
            if lookahead.peek(kw::name) {
                if args.name.is_some() {
                    return Err(input.error("expected only a single `name` argument"));
                }
                let name = input.parse::<StrArg<kw::name>>()?.value;
                args.name = Some(name);
            } else {
                // TODO - may want to warn here when found a invalid arg - see how
                // tracing::instrument stores warnings and emits them later when generating the
                // expanded token stream.
                let _ = input.parse::<proc_macro2::TokenTree>();
            }
        }
        Ok(args)
    }
}

mod kw {
    syn::custom_keyword!(name);
}