Skip to content

Commit c529417

Browse files
committed
feat: ✨ remove need for value for attribute nested
nested = true is no longer needed or even allowed
1 parent bb57441 commit c529417

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

envconfig_derive/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ fn gen_field_assign(field: &Field, source: &Source) -> proc_macro2::TokenStream
9797

9898
// If nested attribute is present
9999
let nested_value_opt = find_item_in_list(&list, "nested");
100-
if nested_value_opt.is_present() {
101-
return gen_field_assign_for_struct_type(field, source);
100+
match nested_value_opt {
101+
MatchingItem::NoValue => return gen_field_assign_for_struct_type(field, source),
102+
MatchingItem::WithValue(_) => {
103+
panic!("`nested` attribute must not have a value")
104+
}
105+
MatchingItem::None => {}
102106
}
103107

104108
// Default value for the field
@@ -262,15 +266,6 @@ enum MatchingItem<'a> {
262266
None,
263267
}
264268

265-
impl<'a> MatchingItem<'a> {
266-
fn is_present(&self) -> bool {
267-
match self {
268-
MatchingItem::WithValue(_) | MatchingItem::NoValue => true,
269-
MatchingItem::None => false,
270-
}
271-
}
272-
}
273-
274269
/// Tries to find the first matching item in the provided list
275270
///
276271
/// # Returns

test_suite/tests/nested.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ pub struct DBConfig {
1414

1515
#[derive(Envconfig)]
1616
pub struct Config {
17-
#[envconfig(nested = true)]
17+
#[envconfig(nested)]
1818
pub db: DBConfig,
1919
}
2020

2121
#[derive(Envconfig)]
2222
pub struct ConfigDouble {
23-
#[envconfig(nested = true)]
23+
#[envconfig(nested)]
2424
pub db1: DBConfig,
2525

26-
#[envconfig(nested = true)]
26+
#[envconfig(nested)]
2727
pub db2: DBConfig,
2828
}
2929

0 commit comments

Comments
 (0)