Write file load/save helpers for Image
This commit is contained in:
1 parent
bab002fefd
commit
af65f622a6
1 file changed
+12
@@ -111,3 +111,15 @@ impl From<std::io::Error> for Error {
|
|||||||
Error::Io(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user