mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-22 03:09:31 +01:00
Improve formatting slightly
This commit is contained in:
@@ -147,28 +147,25 @@ fn gen_partial_mod(input: &ir::Input) -> TokenStream {
|
||||
}
|
||||
});
|
||||
|
||||
let from_env_fields = input.fields.iter().map(|f| match &f.kind {
|
||||
FieldKind::Leaf {
|
||||
env: Some(key),
|
||||
deserialize_with,
|
||||
parse_env,
|
||||
..
|
||||
} => {
|
||||
let field = format!("{}::{}", input.name, f.name);
|
||||
match (parse_env, deserialize_with) {
|
||||
(None, None) => quote! {
|
||||
confique::internal::from_env(#key, #field)?
|
||||
},
|
||||
(None, Some(deserialize_with)) => quote! {
|
||||
confique::internal::deserialize_from_env_with(#key, #field, #deserialize_with)?
|
||||
},
|
||||
(Some(parse_env), None) | (Some(parse_env), Some(_)) => quote! {
|
||||
confique::internal::parse_from_env_with(#key, #field, #parse_env)?
|
||||
},
|
||||
let from_env_fields = input.fields.iter().map(|f| {
|
||||
match &f.kind {
|
||||
FieldKind::Leaf { env: Some(key), deserialize_with, parse_env, .. } => {
|
||||
let field = format!("{}::{}", input.name, f.name);
|
||||
match (parse_env, deserialize_with) {
|
||||
(None, None) => quote! {
|
||||
confique::internal::from_env(#key, #field)?
|
||||
},
|
||||
(None, Some(deserialize_with)) => quote! {
|
||||
confique::internal::deserialize_from_env_with(#key, #field, #deserialize_with)?
|
||||
},
|
||||
(Some(parse_env), None) | (Some(parse_env), Some(_)) => quote! {
|
||||
confique::internal::parse_from_env_with(#key, #field, #parse_env)?
|
||||
},
|
||||
}
|
||||
}
|
||||
FieldKind::Leaf { .. } => quote! { None },
|
||||
FieldKind::Nested { .. } => quote! { confique::Partial::from_env()? },
|
||||
}
|
||||
FieldKind::Leaf { .. } => quote! { None },
|
||||
FieldKind::Nested { .. } => quote! { confique::Partial::from_env()? },
|
||||
});
|
||||
|
||||
let fallbacks = input.fields.iter().map(|f| {
|
||||
|
||||
@@ -71,21 +71,24 @@ impl Field {
|
||||
"A `parse_env` attribute, cannot be provided without the `env` attribute",
|
||||
));
|
||||
}
|
||||
|
||||
let kind = match unwrap_option(&field.ty) {
|
||||
Some(_) if attrs.default.is_some() => {
|
||||
return Err(Error::new(
|
||||
field.ident.span(),
|
||||
"optional fields (type `Option<_>`) cannot have default \
|
||||
values (`#[config(default = ...)]`)",
|
||||
));
|
||||
},
|
||||
Some(inner) => LeafKind::Optional { inner_ty: inner.clone() },
|
||||
None => LeafKind::Required { default: attrs.default, ty: field.ty },
|
||||
};
|
||||
|
||||
FieldKind::Leaf {
|
||||
env: attrs.env,
|
||||
deserialize_with: attrs.deserialize_with,
|
||||
parse_env: attrs.parse_env,
|
||||
kind: match unwrap_option(&field.ty) {
|
||||
Some(_inner) if attrs.default.is_some() => {
|
||||
return Err(Error::new(
|
||||
field.ident.span(),
|
||||
"optional fields (type `Option<_>`) cannot have default \
|
||||
values (`#[config(default = ...)]`)",
|
||||
));
|
||||
},
|
||||
Some(inner) => LeafKind::Optional { inner_ty: inner.clone() },
|
||||
None => LeafKind::Required { default: attrs.default, ty: field.ty },
|
||||
},
|
||||
kind,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ impl<'de> serde::Deserializer<'de> for Deserializer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user