Skip to content

Commit

Permalink
Bump syn / quote / proc-macro2
Browse files Browse the repository at this point in the history
Closes #28
  • Loading branch information
yukinarit committed Jul 27, 2024
1 parent 4b0a10e commit 8b100ed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 70 deletions.
53 changes: 9 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions econf-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 25 additions & 22 deletions econf-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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::<Ident>() {
return args == "skip";
}
}

false
})
}

fn find_renaming(f: &Field) -> Option<String> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion econf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8b100ed

Please sign in to comment.