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
use std::path::PathBuf;
use crate::errors::DiaryError;
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
diary_path: PathBuf,
prefix: String,
}
impl Config {
pub fn new(diary_path: PathBuf, prefix: String) -> Self {
Config { diary_path, prefix }
}
pub fn diary_path(&self) -> &PathBuf {
&self.diary_path
}
pub fn prefix(&self) -> &String {
&self.prefix
}
pub fn initialised(&self) -> Result<(), DiaryError> {
if self.diary_path == PathBuf::from("") {
Err(DiaryError::UnInitialised { source: None })
} else {
Ok(())
}
}
}
impl ::std::default::Default for Config {
fn default() -> Self {
Self {
diary_path: PathBuf::from(""),
prefix: String::from("diary"),
}
}
}