Skip to content

Commit

Permalink
fix: skip EnvField automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Nov 6, 2023
1 parent 9df317c commit ef8caf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion env-field-wrap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "serde-env-field-wrap"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "An attribute that wraps all the fields of a struct or an enum with the EnvField type"
license = "MIT"
Expand Down
11 changes: 6 additions & 5 deletions env-field-wrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn take_env_field_wrap_attr(attrs: &mut Vec<syn::Attribute>) -> Option<WrapAttr>
})
}

fn is_type(ty: &syn::Type, unqualified: &str, qualified: &[&str]) -> bool {
fn is_type(ty: &syn::Type, ty_paths: &[&str]) -> bool {
match ty {
syn::Type::Path(ty_path) if ty_path.qself.is_none() => {
let path = &ty_path.path;
Expand All @@ -90,7 +90,7 @@ fn is_type(ty: &syn::Type, unqualified: &str, qualified: &[&str]) -> bool {
// Remove the last `::`
let path_ty_str = &path_ty_str[..path_ty_str.len() - 2];

path_ty_str == unqualified || qualified.iter().any(|ty| *ty == path_ty_str)
ty_paths.iter().any(|ty| *ty == path_ty_str)
}
_ => false,
}
Expand Down Expand Up @@ -170,11 +170,12 @@ fn process_fields(fields: impl Iterator<Item = syn::Field>) -> TokenStream2 {
None => {
if is_type(
&ty,
"Option",
&["std::option::Option", "core::option::Option"],
) || is_type(&ty, "Vec", &["std::vec::Vec", "alloc::vec::Vec"])
&["Option", "std::option::Option", "core::option::Option"],
) || is_type(&ty, &["Vec", "std::vec::Vec", "alloc::vec::Vec"])
{
wrap_generics_only(&ty)
} else if is_type(&ty, &["EnvField", "serde_env_field::EnvField"]) {
quote!(#ty)
} else {
quote!(::serde_env_field::EnvField<#ty>)
}
Expand Down

0 comments on commit ef8caf1

Please sign in to comment.