orion_infra/config/
traits.rs1use log::warn;
2use orion_conf::error::OrionConfResult;
3
4pub trait ConfigLifecycle {
6 fn try_load(path: &str) -> Option<Self>
8 where
9 Self: Sized,
10 {
11 if std::path::Path::new(path).exists() {
12 match Self::load(path) {
13 Ok(conf) => Some(conf),
14 Err(e) => {
15 warn!("load conf error: {e}");
16 None
17 }
18 }
19 } else {
20 None
21 }
22 }
23
24 fn load(path: &str) -> OrionConfResult<Self>
26 where
27 Self: Sized;
28
29 fn init(&self, path: &str) -> OrionConfResult<()>
31 where
32 Self: Sized;
33
34 fn safe_clean(path: &str) -> OrionConfResult<()>;
36 fn save(&self, path: &str) -> OrionConfResult<()>;
37}