Skip to content

Commit 62c6fcf

Browse files
committed
Move attribute arg parsing to module
1 parent d9f7a46 commit 62c6fcf

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/args.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use syn::parse::{Parse, ParseStream, Result};
2+
3+
pub struct Args {
4+
pub local: bool
5+
}
6+
7+
mod kw {
8+
syn::custom_keyword!(local);
9+
}
10+
11+
impl Parse for Args {
12+
fn parse(input: ParseStream) -> Result<Self> {
13+
let local: Option<kw::local> = input.parse()?;
14+
Ok(Args {
15+
local: local.is_some(),
16+
})
17+
}
18+
}

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,23 @@
299299
300300
extern crate proc_macro;
301301

302+
mod args;
302303
mod expand;
303304
mod lifetime;
304305
mod parse;
305306
mod receiver;
306307

308+
use crate::args::Args;
307309
use crate::expand::expand;
308310
use crate::parse::Item;
309311
use proc_macro::TokenStream;
310312
use quote::quote;
311313
use syn::parse_macro_input;
312314

313-
mod kw {
314-
syn::custom_keyword!(local);
315-
}
316-
317315
#[proc_macro_attribute]
318316
pub fn async_trait(args: TokenStream, input: TokenStream) -> TokenStream {
319-
let local = parse_macro_input!(args as Option<kw::local>).is_some();
317+
let args = parse_macro_input!(args as Args);
320318
let mut item = parse_macro_input!(input as Item);
321-
expand(&mut item, local);
319+
expand(&mut item, args.local);
322320
TokenStream::from(quote!(#item))
323321
}

0 commit comments

Comments
 (0)