use crate::error::Error;
use crate::fs::File;
use crate::format::FileFormat;
use std::path::Path;
pub fn read<T, Format>(path: impl AsRef<Path>, format: Format) -> Result<T, Error<Format::FormatError>>
where Format: FileFormat<T> {
let file = File::open(path.as_ref())?;
let value = format.from_reader_buffered(file).map_err(Error::Format)?;
Ok(value)
}
pub fn write<T, Format>(path: impl AsRef<Path>, format: Format, value: &T) -> Result<(), Error<Format::FormatError>>
where Format: FileFormat<T> {
let file = File::create(path.as_ref())?;
format.to_writer_buffered(file, value).map_err(Error::Format)?;
Ok(())
}