mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-07 04:01:26 +01:00
Rename #[config(child)] to #[config(nested)]
This commit is contained in:
@@ -3,10 +3,10 @@ use confique::Config;
|
||||
|
||||
#[derive(Debug, Config)]
|
||||
struct Conf {
|
||||
#[config(child)]
|
||||
#[config(nested)]
|
||||
http: Http,
|
||||
|
||||
#[config(child)]
|
||||
#[config(nested)]
|
||||
cat: Cat,
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ fn gen_partial_mod(input: &ir::Input) -> TokenStream {
|
||||
Some(confique::internal::deserialize_default(#default).expect(#msg))
|
||||
}
|
||||
}
|
||||
FieldKind::Child => {
|
||||
FieldKind::Nested => {
|
||||
if unwrap_option(&f.ty).is_some() {
|
||||
quote! { Some(confique::Partial::default_values()) }
|
||||
} else {
|
||||
@@ -166,10 +166,10 @@ fn gen_meta(input: &ir::Input) -> TokenStream {
|
||||
let name = f.name.to_string();
|
||||
let doc = &f.doc;
|
||||
let kind = match &f.kind {
|
||||
FieldKind::Child => {
|
||||
FieldKind::Nested => {
|
||||
let ty = &f.ty;
|
||||
quote! {
|
||||
confique::meta::FieldKind::Child { meta: &<#ty as confique::Config>::META }
|
||||
confique::meta::FieldKind::Nested { meta: &<#ty as confique::Config>::META }
|
||||
}
|
||||
}
|
||||
FieldKind::Leaf { default } => {
|
||||
|
||||
@@ -30,7 +30,7 @@ pub(crate) enum FieldKind {
|
||||
Leaf {
|
||||
default: Option<Expr>,
|
||||
},
|
||||
Child,
|
||||
Nested,
|
||||
}
|
||||
|
||||
/// The kinds of expressions (just literals) we allow for default or example
|
||||
@@ -75,15 +75,15 @@ impl Field {
|
||||
let attrs = extract_internal_attrs(&mut field.attrs)?;
|
||||
|
||||
// TODO: check no other attributes are here
|
||||
let kind = if attrs.child {
|
||||
let kind = if attrs.nested {
|
||||
if attrs.default.is_some() {
|
||||
return Err(Error::new(
|
||||
field.ident.span(),
|
||||
"cannot specify `child` and `default` attributes at the same time",
|
||||
"cannot specify `nested` and `default` attributes at the same time",
|
||||
));
|
||||
}
|
||||
|
||||
FieldKind::Child
|
||||
FieldKind::Nested
|
||||
} else {
|
||||
FieldKind::Leaf {
|
||||
default: attrs.default,
|
||||
@@ -186,9 +186,9 @@ fn extract_internal_attrs(
|
||||
duplicate_if!(out.default.is_some());
|
||||
out.default = Some(expr);
|
||||
}
|
||||
InternalAttr::Child => {
|
||||
duplicate_if!(out.child);
|
||||
out.child = true;
|
||||
InternalAttr::Nested => {
|
||||
duplicate_if!(out.nested);
|
||||
out.nested = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,19 +198,19 @@ fn extract_internal_attrs(
|
||||
|
||||
#[derive(Default)]
|
||||
struct InternalAttrs {
|
||||
child: bool,
|
||||
nested: bool,
|
||||
default: Option<Expr>,
|
||||
}
|
||||
|
||||
enum InternalAttr {
|
||||
Child,
|
||||
Nested,
|
||||
Default(Expr),
|
||||
}
|
||||
|
||||
impl InternalAttr {
|
||||
fn keyword(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Child => "child",
|
||||
Self::Nested => "nested",
|
||||
Self::Default(_) => "default",
|
||||
}
|
||||
}
|
||||
@@ -220,9 +220,9 @@ impl Parse for InternalAttr {
|
||||
fn parse(input: ParseStream) -> Result<Self, syn::Error> {
|
||||
let ident: syn::Ident = input.parse()?;
|
||||
match &*ident.to_string() {
|
||||
"child" => {
|
||||
"nested" => {
|
||||
assert_empty(input)?;
|
||||
Ok(Self::Child)
|
||||
Ok(Self::Nested)
|
||||
}
|
||||
"default" => {
|
||||
let _: Token![=] = input.parse()?;
|
||||
|
||||
@@ -28,7 +28,7 @@ pub enum FieldKind {
|
||||
Leaf {
|
||||
default: Option<Expr>,
|
||||
},
|
||||
Child {
|
||||
Nested {
|
||||
meta: &'static Meta,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user