use anyhow::Result;
pub struct Loader;
impl Loader {
pub fn new() -> Self {
Self
}
pub async fn load_yaml<T>(&self, path: &std::path::Path) -> Result<T>
where
T: serde::de::DeserializeOwned,
{
let content = tokio::fs::read_to_string(path).await?;
Ok(serde_yaml::from_str(&content)?)
}
pub async fn load_json<T>(&self, path: &std::path::Path) -> Result<T>
where
T: serde::de::DeserializeOwned,
{
let content = tokio::fs::read_to_string(path).await?;
Ok(serde_json::from_str(&content)?)
}
}
impl Default for Loader {
fn default() -> Self {
Self::new()
}
}