#[cfg(feature = "yaml")]
pub mod featured {
use serde::{Deserialize, Serialize};
use std::fs::{read_to_string, write};
use std::path::Path;
pub trait FromYaml: for<'de> Deserialize<'de> {
fn from_yaml_file(filename: impl AsRef<Path>) -> anyhow::Result<Self> {
<Self as FromYaml>::from_yaml_string(&read_to_string(filename)?)
}
fn from_yaml_string(text: &str) -> anyhow::Result<Self> {
Ok(serde_yaml::from_str(text)?)
}
}
pub trait ToYaml: Serialize {
fn to_yaml(&self) -> anyhow::Result<String> {
Ok(serde_yaml::to_string(self)?)
}
fn write_to_yaml_file(&self, filename: impl AsRef<Path>) -> anyhow::Result<()> {
Ok(write(filename, <Self as ToYaml>::to_yaml(self)?)?)
}
}
}