greyblake/envconfig-rs

Extract an env variable from several possible keys?

Keksoj opened this issue · 5 comments

This crate fits all my needs up to a feature I'd like to see:

#[derive(Envconfig)]
struct Config {
    #[envconfig(from = "POSTGRESQL_URL", or_from = "POSTGRES_URL")]
    pub postgresql_url: String,
}

Because I may need to run a binary that will run with different environments where the env variables may have slightly different names. The level of priority for each of these names could be determined by their order.

@Keksoj This seems to be a very exotic use case!

What do you think about this?

#[derive(Envconfig)]
struct Config {
    #[envconfig(from = ["POSTGRESQL_URL", "POSTGRES_URL"])]
    pub postgresql_url: String,
}

@Keksoj Interalie.. Ĉu vi estas samideano? :D

I like your idea (samideano!) but your syntax yields this:

error: proc-macro derive panicked
 --> src/config.rs:9:24
  |
9 | #[derive(Clone, Debug, Envconfig)]
  |                        ^^^^^^^^^
  |
  = help: message: Can not interpret meta of `envconfig` attribute on field `postgresql_url`: expected literal

Would love for it to work though.

(@greyblake kara samlingvano! De terure longa tempo mi ne babilis la lingvon. Mi nostalgias iom ;-) )

@Keksoj It's not yet implemented, just an alternative proposal.

P.S. Malfermu bieron, kaj lasu nin babili :)
@AlisCode Ĉu vi volas aliĝi? :D

@greyblake mi ĝojas babili kaj bierumi sed ĉi tie ne plej bonas. Ni provu kontakti unu la alian alimaniere.