Skip to content

zphixon/from_env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

from_env

Define a configuration structure which implements Deserialize, and whose values can be overridden by setting environment variables.

For example:

// Defines a struct `Config`
from_env::config!(
    // Define a base type name, this will the the environment variable namespace
    "TestStuff",

    // Define some config values. These must implement FromStr and Deserialize
    hello: String,
    network {
        // Mappings are also possible
        address: SocketAddr,
        database_url: Url,
    }
);
hello = "world"

[network]
address = "0.0.0.0:5000"
database_url = "mysql://root:password@localhost:3306/database"
{
    "hello": "world",
    "network": {
        "address": "0.0.0.0:5000",
        "database_url": "mysql://root:password@localhost:3306/database"
    }
}
let mut config: Config = toml::from_str(config_contents).unwrap();
let mut config: Config = serde_json::from_str(config_contents).unwrap();

// Call hydrate_from_env to override with env vars
config.hydrate_from_env();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages