pub fn init(self) -> Result<Configuration, ConfigError> {
        let mut config = Configuration::new();

        // Layer 0, cargo dev envs.
        if let Some(cargo) = self.cargo {
            config = config.register_source(cargo)?;
        }

        // Layer 1, commandlines.
        config = config.register_source(self.memory)?;

        let option: SourceOption = config.get_predefined()?;

        // Layer 2, random
        #[cfg(feature = "rand")]
        if option.random.enabled {
            config = config.register_random()?;
        }

        // Layer 3, environment.
        let prefix = self
            .prefix
            .or_else(|| config.get::<Option<String>>("env.prefix").ok().flatten())
            .or_else(|| var("CFG_ENV_PREFIX").ok())
            .unwrap_or_else(|| "CFG".to_owned());
        config = config.register_prefix_env(&prefix)?;

        if let Some(init) = self.init {
            (init)(&config)?;
            cfg_log!(log::Level::Info, "Early initialization completed.");
        }

        // Layer 4, profile file.
        let app = config.get_predefined::<AppConfig>()?;
        let mut path = PathBuf::new();
        if let Some(d) = app.dir {
            path.push(d);
        };
        if let Some(profile) = &app.profile {
            let mut path = path.clone();
            path.push(format!("{}-{}", app.name, profile));
            config = register_files(config, &option, path, false)?;
        }

        // Layer 5, file.
        path.push(app.name);
        config = register_files(config, &option, path, false)?;

        cfg_log!(
            log::Level::Info,
            "Predefined configuration initialization completed."
        );
        Ok(config)
    }
/// Initialize configuration by multiple predefined sources.
///
/// ## Predefined Sources.
///
/// 0. Cargo Package Env Variables (Must be explicitly set by [set_cargo_env](struct.PredefinedConfigurationBuilder.html#method.set_cargo_env)).
/// 1. Customized by Programming or Commandline Args.[^f_default]
/// 2. Random Value (Auto enabled with feature `rand`).
/// 3. Environment Variable with Prefix `CFG`, referto [set_prefix_env](struct.PredefinedConfigurationBuilder.html#method.set_prefix_env) for details.[^f_default]
/// 4. Profiled File Source with Path, `${app.dir}/${app.name}-${app.profile}.EXT`. EXT: toml, json, yaml.[^f_file]
/// 5. File Source with Path, `${app.dir}/${app.name}.EXT`. EXT: toml, json, yaml.[^f_file]
/// 6. Customized Source Can be Registered by [register_source](struct.Configuration.html#method.register_source).
///
/// [^f_default]: Always be enabled.
///
/// [^f_file]: See [Supported File Formats](index.html#supported-file-format) for details.
///
/// ## Crate Feature
///
/// * Feature `rand` to enable random value source.
/// * Feature `toml` to enable toml supports.
/// * Feature `yaml` to enable yaml supports.
/// * Feature `json` to enable json supports.
Initialize configuration by multiple predefined sources.
Initialize configuration by multiple predefined sources .
pub fn init(self) -> Result<Configuration, ConfigError> {
        let mut config = Configuration::new();
        // Layer 0, cargo dev envs.
        if let Some(cargo) = self.cargo {
            config = config.register_source(cargo)?;
        }
        // Layer 1, commandlines.
        config = config.register_source(self.memory)?;
        let option: SourceOption = config.get_predefined()?;
        // Layer 2, random
        #[cfg(feature = "rand")]
        if option.random.enabled {
            config = config.register_random()?;
        }
        // Layer 3, environment.
        let prefix = self
            .prefix
            .or_else(|| config.get::<Option<String>>("env.prefix").ok().flatten())
            .or_else(|| var("CFG_ENV_PREFIX").ok())
            .unwrap_or_else(|| "CFG".to_owned());
        config = config.register_prefix_env(&prefix)?;
        if let Some(init) = self.init {
            (init)(&config)?;
            cfg_log!(log::Level::Info, "Early initialization completed.");
        }
        // Layer 4, profile file.
        let app = config.get_predefined::<AppConfig>()?;
        let mut path = PathBuf::new();
        if let Some(d) = app.dir {
            path.push(d);
        };
        if let Some(profile) = &app.profile {
            let mut path = path.clone();
            path.push(format!("{}-{}", app.name, profile));
            config = register_files(config, &option, path, false)?;
        }
        // Layer 5, file.
        path.push(app.name);
        config = register_files(config, &option, path, false)?;
        cfg_log!(
            log::Level::Info,
            "Predefined configuration initialization completed."
        );
        Ok(config)
    }
pub fn init ( self ) -> Result < Configuration , ConfigError > { let mut config = Configuration :: new ( ) ; // Layer 0, cargo dev envs. if let Some ( cargo ) = self . cargo { config = config . register_source ( cargo ) ? ; } // Layer 1, commandlines. config = config . register_source ( self . memory ) ? ; let option : SourceOption = config . get_predefined ( ) ? ; // Layer 2, random # [ cfg ( feature " " ) ] if option . random . enabled { config = config . register_random ( ) ? ; } // Layer 3, environment. let prefix = self . prefix . or_else ( | | config . get :: < Option < String > > ( " " ) . ok ( ) . flatten ( ) ) . or_else ( | | var ( " " ) . ok ( ) ) . unwrap_or_else ( | | " " . to_owned ( ) ) ; config = config . register_prefix_env ( & prefix ) ? ; if let Some ( init ) = self . init { ( init ) ( & config ) ? ; cfg_log ! ( log Level Info " " ) ; } // Layer 4, profile file. let app = config . get_predefined :: < AppConfig > ( ) ? ; let mut path = PathBuf :: new ( ) ; if let Some ( d ) = app . dir { path . push ( d ) ; } ; if let Some ( profile ) = & app . profile { let mut path = path . clone ( ) ; path . push ( format ! ( " " app name profile ) ) ; config = register_files ( config , & option , path , false ) ? ; } // Layer 5, file. path . push ( app . name ) ; config = register_files ( config , & option , path , false ) ? ; cfg_log ! ( log Level Info " " ) ; Ok ( config ) }
Initialize configuration by multiple predefined sources.
Initialize configuration by multiple predefined sources .
self
self
predefined sources.
0. Cargo Package Env Variables (Must be explicitly set by [set_cargo_env](struct.PredefinedConfigurationBuilder.html#method.set_cargo_env)).
1. Customized by Programming or Commandline Args.[^f_default]
2. Random Value (Auto enabled with feature `rand`).
3. Environment Variable with Prefix `CFG`, referto [set_prefix_env](struct.PredefinedConfigurationBuilder.html#method.set_prefix_env) for details.[^f_default]
4. Profiled File Source with Path, `${app.dir}/${app.name}-${app.profile}.EXT`. EXT: toml, json, yaml.[^f_file]
5. File Source with Path, `${app.dir}/${app.name}.EXT`. EXT: toml, json, yaml.[^f_file]
6. Customized Source Can be Registered by [register_source](struct.Configuration.html#method.register_source).

[^f_default]: Always be enabled.

[^f_file]: See [Supported File Formats](index.html#supported-file-format) for details.
0 . Cargo Package Env Variables ( Must be explicitly set by [ set_cargo_env ] ( struct . PredefinedConfigurationBuilder . html#method . set_cargo_env )) . 1 . Customized by Programming or Commandline Args . [ ^f_default ] 2 . Random Value ( Auto enabled with feature ` rand ` ) . 3 . Environment Variable with Prefix ` CFG ` referto [ set_prefix_env ] ( struct . PredefinedConfigurationBuilder . html#method . set_prefix_env ) for details . [ ^f_default ] 4 . Profiled File Source with Path ` $ { app . dir } / $ { app . name } - $ { app . profile } . EXT ` . EXT : toml json yaml . [ ^f_file ] 5 . File Source with Path ` $ { app . dir } / $ { app . name } . EXT ` . EXT : toml json yaml . [ ^f_file ] 6 . Customized Source Can be Registered by [ register_source ] ( struct . Configuration . html#method . register_source ) . [ ^f_default ] : Always be enabled . [ ^f_file ] : See [ Supported File Formats ] ( index . html#supported - file - format ) for details .
crate feature
Feature `rand` to enable random value source.
Feature `toml` to enable toml supports.
Feature `yaml` to enable yaml supports.
Feature `json` to enable json supports.
Feature ` rand ` to enable random value source . Feature ` toml ` to enable toml supports . Feature ` yaml ` to enable yaml supports . Feature ` json ` to enable json supports .