use std::fs::{read_to_string, write};
use std::path::Path;
use serde::Serialize;
use serde::de::DeserializeOwned;
#[allow(clippy::module_name_repetitions)]
pub trait FromToml: DeserializeOwned {
fn from_toml_file(filename: impl AsRef<Path>) -> crate::Result<Self> {
<Self as FromToml>::from_toml_string(&read_to_string(filename)?)
}
fn from_toml_string(text: &str) -> crate::Result<Self> {
Ok(toml::from_str(text)?)
}
}
#[allow(clippy::module_name_repetitions)]
pub trait ToToml: Serialize {
fn to_toml(&self) -> crate::Result<String> {
Ok(toml::to_string(self)?)
}
fn write_to_toml_file(&self, filename: impl AsRef<Path>) -> crate::Result<()> {
Ok(write(filename, <Self as ToToml>::to_toml(self)?)?)
}
}