Skip to content

A normal macro for loading env vars and stuff I guess #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 30, 2025

Conversation

prestwich
Copy link
Member

No description provided.

@prestwich prestwich force-pushed the prestwich/from-env-macro branch from 8062790 to 210577f Compare April 25, 2025 12:44
@prestwich prestwich force-pushed the prestwich/from-env-macro branch from 210577f to cc31fed Compare April 25, 2025 12:45
@Evalir Evalir self-requested a review April 29, 2025 10:21
Comment on lines +105 to +114
pub(crate) fn field_name(&self, idx: usize) -> Ident {
if let Some(field_name) = self.field_name.as_ref() {
return field_name.clone();
}

let n = format!("field_{}", idx);
syn::parse_str::<Ident>(&n)
.map_err(|_| syn::Error::new(self.span, "Failed to create field name"))
.unwrap()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so for tuple structs, we'd get instead of the struct prop name, field_0, field_1...,field_n and so forth? This seems fine to me to support tuple structs although I'm not sure in which cases you'd want to do a config with a tuple struct.

use init4_from_env_derive::FromEnv;

#[derive(FromEnv, Debug)]
pub struct FromEnvTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably add a test with a tuple struct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. this is really nice :)

@prestwich prestwich merged commit df9abb0 into main Apr 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants