1mod defaults;
4mod model;
5mod peer;
6mod peer_cleanup;
7
8#[cfg(test)]
9mod tests;
10
11pub use model::*;
12pub use peer::*;
13pub use peer_cleanup::PeerCleanupConfig;
14
15use std::path::Path;
16use std::str::FromStr;
17
18use crate::PimError;
19
20impl Config {
21 pub fn load(path: &Path) -> Result<Self, PimError> {
23 let content = std::fs::read_to_string(path).map_err(PimError::Io)?;
24 content.parse()
25 }
26
27 pub fn from_toml_str(s: &str) -> Result<Self, PimError> {
29 s.parse()
30 }
31
32 pub fn to_toml_string(&self) -> Result<String, PimError> {
34 toml::to_string_pretty(self).map_err(|e| PimError::Config(e.to_string()))
35 }
36}
37
38impl FromStr for Config {
39 type Err = PimError;
40
41 fn from_str(s: &str) -> Result<Self, Self::Err> {
42 toml::from_str(s).map_err(|e| PimError::Config(e.to_string()))
43 }
44}