Write file load/save helpers for Image

This commit is contained in:
cdo committed 2026-10-25 22:24:52 +00:00
1 parent bab002fefd
commit af65f622a6
1 file changed
+12
+12
View File
@@ -111,3 +111,15 @@ impl From<std::io::Error> for Error {
Error::Io(error)
}
}
impl Image {
pub fn load<F: Format>(path: &str) -> Result<Image, Error> {
let file = std::fs::File::open(path)?;
F::read(&mut std::io::BufReader::new(file))
}
pub fn save<F: Format>(&self, path: &str) -> std::io::Result<()> {
let file = std::fs::File::create(path)?;
F::write(&mut std::io::BufWriter::new(file), self)
}
}