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