#[cfg(feature = "toml")]
pub mod featured {
use crate::Error;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::fs::{read_to_string, write};
pub trait FromToml: DeserializeOwned {
fn from_toml_file(filename: &str) -> Result<Self, Error> {
read_to_string(filename)
.map_err(Error::FileError)
.and_then(|text| <Self as FromToml>::from_toml_string(&text))
}
fn from_toml_string(text: &str) -> Result<Self, Error> {
toml::from_str(text).map_err(|error| Error::SerdeError(error.to_string()))
}
}
pub trait ToToml: Serialize {
fn to_toml(&self) -> Result<String, Error> {
toml::to_string(self).map_err(|error| Error::SerdeError(error.to_string()))
}
fn write_to_toml_file(&self, filename: &str) -> Result<(), Error> {
write(filename, <Self as ToToml>::to_toml(self)?).map_err(Error::FileError)
}
}
}