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
47
48
49
50
51
52
53
54
55
56
use paste::paste;
use crate::{dirs, config::Config};
#[doc(hidden)]
macro_rules! gen_dirs {
($($dir_name:expr),*) => {
$(
paste! {
#[doc = " PathBuf for App's `" $dir_name "` directory."]
pub fn [<$dir_name _dir>](&self) -> std::path::PathBuf {
dirs::[<$dir_name _dir>]().join(&self.name)
}
}
)*
}
}
#[derive(Debug)]
pub struct App {
name: &'static str,
config_file: Option<&'static str>,
}
impl App {
pub fn config(&self) -> Config {
let dir = dirs::config_dir().join(self.name);
let file = self.config_file.unwrap_or("config");
Config::from(dir, file)
}
pub fn config_file(&self, file: &'static str) -> Config {
let dir = dirs::config_dir().join(self.name);
Config::from(dir, file)
}
gen_dirs! {"cache", "config", "data", "data_local", "preference"}
}
pub const fn app(name: &'static str, config_file: Option<&'static str>) -> App {
App { name, config_file }
}