diff --git a/Cargo.lock b/Cargo.lock index 7f30e0f..6b36acf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,9 +49,9 @@ dependencies = [ name = "econf-derive" version = "0.2.1" dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -130,15 +130,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "proc-macro2" -version = "0.4.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -dependencies = [ - "unicode-xid", -] - [[package]] name = "proc-macro2" version = "1.0.86" @@ -148,22 +139,13 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quote" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -dependencies = [ - "proc-macro2 0.4.30", -] - [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.86", + "proc-macro2", ] [[package]] @@ -187,9 +169,9 @@ version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ - "proc-macro2 1.0.86", - "quote 1.0.36", - "syn 2.0.68", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -216,25 +198,14 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "syn" -version = "0.15.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "unicode-xid", -] - [[package]] name = "syn" version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ - "proc-macro2 1.0.86", - "quote 1.0.36", + "proc-macro2", + "quote", "unicode-ident", ] @@ -277,12 +248,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-xid" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/econf-derive/Cargo.toml b/econf-derive/Cargo.toml index 2307a88..1f50c68 100644 --- a/econf-derive/Cargo.toml +++ b/econf-derive/Cargo.toml @@ -11,9 +11,9 @@ repository = "https://github.com/YushiOMOTE/econf" readme = "README.md" [dependencies] -syn = "0.15" -quote = "0.6" -proc-macro2 = "0.4" +syn = "2" +quote = "1" +proc-macro2 = "1" [lib] proc-macro = true diff --git a/econf-derive/src/lib.rs b/econf-derive/src/lib.rs index 4d98f4d..f459f18 100644 --- a/econf-derive/src/lib.rs +++ b/econf-derive/src/lib.rs @@ -4,7 +4,7 @@ use proc_macro::TokenStream; use proc_macro2::{Ident, TokenStream as TokenStream2}; use quote::quote; -use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, Lit, Meta, NestedMeta}; +use syn::{parse_macro_input, Data, DeriveInput, Field, Fields, LitStr}; #[proc_macro_derive(LoadEnv, attributes(econf))] pub fn load_env(input: TokenStream) -> TokenStream { @@ -26,31 +26,34 @@ pub fn load_env(input: TokenStream) -> TokenStream { } fn is_skip(f: &Field) -> bool { - f.attrs.iter().any(|a| { - a.path.is_ident("econf") - && matches!(a.parse_meta().unwrap(), Meta::List(meta) if meta.nested.iter().any(|nm| { - matches!(nm, NestedMeta::Meta(Meta::Word(word)) if *word == "skip") - })) + f.attrs.iter().any(|attr| { + if attr.path().is_ident("econf") { + if let Ok(args) = attr.parse_args::() { + return args == "skip"; + } + } + + false }) } fn find_renaming(f: &Field) -> Option { - f.attrs - .iter() - .filter(|attr| attr.path.is_ident("econf")) - .filter_map(|attr| match attr.parse_meta().unwrap() { - Meta::List(meta) => Some(meta.nested), - _ => None, - }) - .flat_map(|nested| nested.into_iter()) - .filter_map(|nested| match nested { - NestedMeta::Meta(Meta::NameValue(value)) if value.ident == "rename" => Some(value), - _ => None, - }) - .find_map(|value| match value.lit { - Lit::Str(token) => Some(token.value()), - _ => None, - }) + let mut rename = None; + for attr in &f.attrs { + if attr.path().is_ident("econf") { + attr.parse_nested_meta(|meta| { + if meta.path.is_ident("rename") { + let s: LitStr = meta.value()?.parse()?; + rename = Some(s.value()); + } + + Ok(()) + }) + .expect("failed to parse nested meta"); + } + } + + rename } fn content(name: &Ident, data: &Data) -> TokenStream2 { diff --git a/econf/Cargo.toml b/econf/Cargo.toml index fc358b2..7400a38 100644 --- a/econf/Cargo.toml +++ b/econf/Cargo.toml @@ -14,7 +14,7 @@ readme = "README.md" log = "0.4" serde = "1.0" serde_yaml = "0.8" -econf-derive = { version = "0.2.1", path = "../econf-derive" } +econf-derive = { path = "../econf-derive" } humantime = "2.1" [dev-dependencies]