#[cfg(feature = "yaml")]
pub mod featured {
use crate::Error;
use serde::{Deserialize, Serialize};
use std::fs::{read_to_string, write};
pub trait FromYaml: for<'de> Deserialize<'de> {
fn from_yaml_file(filename: &str) -> Result<Self, Error> {
read_to_string(filename)
.map_err(Error::FileError)
.and_then(|text| <Self as FromYaml>::from_yaml_string(&text))
}
fn from_yaml_string(text: &str) -> Result<Self, Error> {
serde_yaml::from_str(text).map_err(|error| Error::SerdeError(error.to_string()))
}
}
pub trait ToYaml: Serialize {
fn to_yaml(&self) -> Result<String, Error> {
serde_yaml::to_string(self).map_err(|error| Error::SerdeError(error.to_string()))
}
fn write_to_yaml_file(&self, filename: &str) -> Result<(), Error> {
write(filename, <Self as ToYaml>::to_yaml(self)?).map_err(Error::FileError)
}
}
}