-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Configurable prefix #12
Comments
Neat idea. That's very common. I'll take a look at this next weekend |
A thought just occured to me that you can already accomplish this with a feature built right into serde. You can tell serde to rename a field on a field by field basis. here is an example $ FOO_BAR=test cargo run --example prefixed
FOO_BAR=test cargo run --example prefixed
Compiling envy v0.3.1 (file:///Users/dougtangren/code/rust/envy)
Finished dev [unoptimized + debuginfo] target(s) in 1.27 secs
Running `/Users/dougtangren/code/rust/envy/target/debug/examples/prefixed`
provided config.bar Some("test") I can see how this would get annoying and would remove some of the convenience of having things just work with a given struct. Serde also has another neat feature where you can rename all fields with a formatter. Unfortunately this doesn't provide a user-defined hook though so it it doesn't really solve for the case you're looking for Im thinking adding a prefix would actually be pretty easy but bit may make the surface area a little wider. Let me think about this a bit. In the mean time let me know how you feel about using the #[serde(rename_all = "prefix(barstool_)")]
struct Config {
// ...
} |
published. this was simple to add check up the updated example you can know use a envy::prefixed("BARSTOOL_").from_env<_>() |
For example if my app is named "barstool" I'll probably be looking for BARSTOOL_BAZ, BARSTOOL_FOO, etc.
The text was updated successfully, but these errors were encountered: