-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfigment.rs
More file actions
40 lines (34 loc) · 1.12 KB
/
figment.rs
File metadata and controls
40 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use conf::Conf;
use figment::{
Figment,
providers::{Format, Json, Toml},
value::Value,
};
use std::env;
#[path = "./common/model_service.rs"]
mod model_service;
use model_service::ModelServiceConfig;
fn main() {
// In this example, we show how figment can be used together with conf
// in order to load content from multiple files, merge them according to
// some hierarchical order, and then supply the result to conf.
//
// This takes advantage of conf's comprehensive error reporting, and gives
// better results than if you just extract() directly into your final
// config structure.
let mut fig = Figment::new();
if let Some(path) = env::var_os("TOML") {
fig = fig.merge(Toml::file(path));
}
if let Some(path) = env::var_os("TOML2") {
fig = fig.merge(Toml::file(path));
}
if let Some(path) = env::var_os("JSON") {
fig = fig.merge(Json::file(path));
}
let doc_content: Value = fig.extract().unwrap();
let config = ModelServiceConfig::conf_builder()
.doc("files", &doc_content)
.parse();
println!("{config:#?}");
}