envconfig-rs icon indicating copy to clipboard operation
envconfig-rs copied to clipboard

Automatically detect name for nested structs

Open dorianim opened this issue 3 years ago • 1 comments

I love this lib, simple and straight forward, thanks!

Just one thing that would be nice to have: In a case like this:

#[derive(Envconfig, Debug)]
struct ProxyAuthConfig {
    enabled: bool,
    headers_username: Option<String>,
    headers_password: Option<String>,
}

#[derive(Envconfig, Debug)]
struct LocalAuthConfig {
    enabled: bool,
}

#[derive(Envconfig, Debug)]
struct AuthConfig {
    #[envconfig(nested = true)]
    proxy: ProxyAuthConfig,
    #[envconfig(nested = true)]
    local: LocalAuthConfig,
}

#[derive(Envconfig, Debug)]
pub struct ConfigurationService {
    jwt_secret: String,

    #[envconfig(nested = true)]
    auth: AuthConfig,
}

the auth.local.enabled would be named AUTH_LOCAL_ENABLED by default :)

dorianim avatar Oct 05 '22 18:10 dorianim

As alternative it would be nice, if a prefix can manual defined at struct level or with the #[envconfig(nested = true)] attribute.

LuckyTurtleDev avatar May 23 '25 21:05 LuckyTurtleDev