Trait configr::Config[][src]

pub trait Config<C> where
    C: DeserializeOwned + Config<C>, 
{ fn populate_template(fd: File) -> Result<()>; fn load(app_name: &str) -> Result<C, ConfigError> { ... }
fn load_with_dir(
        app_name: &str,
        config_dir: &mut PathBuf
    ) -> Result<C, ConfigError> { ... } }
Expand description

This is the main trait that you implement on your struct, either manually or using the Configr derive macro

use configr::{Config, Configr};
#[derive(Configr, serde::Deserialize)]
pub struct BotConfig {
    bot_username: String,
    client_id: String,
    client_secret: String,
    channel: String,
}

let config = BotConfig::load("bot-app").unwrap();

Required methods

Loading content...

Provided methods

fn load(app_name: &str) -> Result<C, ConfigError>[src]

Expand description

Load the config from the config file located in the OS specific config directory
This is a wrapper around load_with_dir, which just takes the system configuration directory, instead of a custom path.
Read load_with_dir for more informationg about failure and config folder structure

Notes

This should in almost every case be prefered over supplying your own configuration directory.

The configuration directory is as follows
Linux: $XDG_CONFIG_HOME/
Windows: %APPDATA%/
Mac OS: $HOME/Library/Application Support/

fn load_with_dir(
    app_name: &str,
    config_dir: &mut PathBuf
) -> Result<C, ConfigError>
[src]

Expand description

Load the config from the config file located in the app specific config directory which is config_dir/app-name/config.toml

Notes

This should only be used in the case you are running this on a system which you know doesn’t have a configuration directory.

The app_name will be converted to lowercase-kebab-case

Failures

This function will Error under the following circumstances

  • If the OS does not have a proper configuration directory
  • If the config.toml or the app-name directory could not be created
  • If the config.toml could not be read properly
  • If the config.toml is not valid toml data
Loading content...

Implementors

Loading content...