-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rs
46 lines (35 loc) · 1000 Bytes
/
config.rs
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
41
42
43
44
45
46
use std::path::PathBuf;
use config::Config;
#[derive(Debug)]
pub struct LoadConfig {
path: PathBuf,
config_data: Config
}
impl Default for LoadConfig {
fn default() -> Self {
let path_name = "./settings.toml";
let path = PathBuf::from(path_name);
let config = Config::builder()
.add_source(config::File::with_name(path_name))
.build()
.expect("builder unable to parse the config file");
Self {
path: path,
config_data: config
}
}
}
impl LoadConfig {
fn new(source: impl AsRef<str>) -> Self {
let path_name = source.as_ref();
let path = PathBuf::from(path_name);
let config = Config::builder()
.add_source(config::File::with_name(path_name))
.build()
.expect("builder unable to parse the config file");
Self {
path: path,
config_data: config
}
}
}