Skip to content
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

feat: Add envconfig annotation for non-nested structs + env_prefix attribute #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Greesb
Copy link

@Greesb Greesb commented May 23, 2023

Hello, I am new to Rust and thought of this feature while using it for another training project.
This should allow to parse environment variables that have a common prefix without having to use that prefix in every variables.

I also took the liberty to update the dependencies to their latest version, except for syn because it would require more work, because i feel like it's always better to have the latest updates for any dependencies if it might improve performance or patch some security issues.

I'll gladly take any input if the code, or even the logic, can be improved in any way.

@Greesb Greesb changed the title feat: Add "env_prefix" attribute for struct derive feat: Add envconfig annotation for non-nested structs + env_prefix attribute May 23, 2023
@Greesb
Copy link
Author

Greesb commented May 27, 2023

Added a commit to upgrade the syn dependency to its latest version

@Greesb Greesb force-pushed the env_prefix branch 3 times, most recently from b8da4e5 to 71e80e9 Compare May 27, 2023 21:32
README.md Outdated Show resolved Hide resolved
envconfig/Cargo.toml Outdated Show resolved Hide resolved
@greyblake
Copy link
Owner

@Greesb Thanks for your PR.

I left some comments.
Could you please also explain why you would need this feature or show a usecase where it solves a pain in your project?

@Greesb
Copy link
Author

Greesb commented May 28, 2023

@Greesb Thanks for your PR.

I left some comments.
Could you please also explain why you would need this feature or show a usecase where it solves a pain in your project?

Thanks for the review, i'll handle them when i get back home.

The use case is that all of our application environment variables have a prefix, so we can avoid env variable "collision", and we want to use, in our application, those environment variables based on their names without the prefix since it's redundant, irrelevant and is way too much verbose.

This attribute allows to add an annotation like so `#[envconfig(env_prefix = "...")]`
on top of a struct. The `env_prefix` will be applied to every config
attribute in the struct.
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