use std::path::Path;
use serde::de::DeserializeOwned;
use crate::error::{Error, Result};
use crate::format::Format;
pub fn load<T>(path: impl AsRef<Path>) -> Result<T>
where
T: DeserializeOwned,
{
let path = path.as_ref();
let format = Format::from_path(path)?;
load_with_format(path, format)
}
pub fn load_with_format<T>(path: impl AsRef<Path>, format: Format) -> Result<T>
where
T: DeserializeOwned,
{
let path = path.as_ref();
let content = std::fs::read_to_string(path).map_err(|source| Error::Read {
path: path.to_path_buf(),
source,
})?;
format.parse(path, &content)
}