Compare commits

...

2 Commits

Author SHA1 Message Date
Dmitry Belyaev 119e9eef22
fix toml save/load 2023-07-11 10:21:43 +03:00
Dmitry Belyaev a516c777c3
upd deps 2023-07-11 10:20:33 +03:00
3 changed files with 586 additions and 283 deletions

856
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,15 +10,15 @@ async-stream = "0.3.3"
clap = { version = "4.0.2", features = ["derive"] }
ctrlc = "3.2.3"
fast-socks5 = "0.8.1"
flexi_logger = { version = "0.23.3", features = ["specfile_without_notification", "async"] }
flexi_logger = { version = "0.25.5", features = ["specfile_without_notification", "async"] }
log = "0.4.17"
serde = { version = "1.0.145", features = ["derive"] }
serde_derive = "1.0.145"
tokio = { version = "1.24.1", features = ["io-std", "net", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.11"
tokio-util = "0.7.4"
toml = "0.5.9"
windows-service = "0.5.0"
toml = "0.7.4"
windows-service = "0.6.0"
[profile.release]
opt-level = 3

View File

@ -66,11 +66,12 @@ impl Default for Config {
impl Config {
const FILENAME: &'static str = "config.toml";
fn read<P: AsRef<Path>>(path: P) -> Result<Self, String> {
let data = fs::read(path).map_err(|e| format!("can't read config: {:?}", e))?;
toml::from_slice(&data).map_err(|e| format!("can't parse config: {:?}", e))
let data = fs::read_to_string(path).map_err(|e| format!("can't read config: {:?}", e))?;
toml::from_str(&data).map_err(|e| format!("can't parse config: {:?}", e))
}
fn write<P: AsRef<Path>>(&self, path: P) -> Result<(), String> {
let data = toml::to_vec(&self).map_err(|e| format!("can't serialize config: {:?}", e))?;
let data = toml::to_string_pretty(&self)
.map_err(|e| format!("can't serialize config: {:?}", e))?;
fs::write(path, &data).map_err(|e| format!("can't write config: {:?}", e))
}
fn file_location() -> Result<PathBuf, String> {