Skip to content

Deriving environment variable names from structs #30

@IgnisDa

Description

@IgnisDa

figment can automatically get names of expected environment variables. With the following config:

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct OpenlibraryConfig {
    pub url: String
}

#[derive(Deserialize, Debug, Clone, Serialize)]
pub struct BookConfig {
    pub openlibrary: OpenlibraryConfig
}

#[derive(Deserialize, Debug, Clone)]
pub struct AppConfig {
    #[serde(default)]
    book: BookConfig
}

let conf: AppConfig = Figment::new().merge(Env::raw().split("_")).extract()?;

The above configuration expects BOOK_OPENLIBRARY_URL, without me having to manually annotate it in the struct. Would be nice if confique supported it as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions