refactor(kra): factor out error mapping
This commit is contained in:
parent
57ad7dfb1e
commit
fca4577c0f
1 changed files with 12 additions and 13 deletions
23
src/kra.rs
23
src/kra.rs
|
|
@ -15,19 +15,9 @@ pub fn register() -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hook<'a>(reader: GenericReader<'a>) -> ImageResult<Box<dyn ImageDecoder + 'a>> {
|
fn hook<'a>(reader: GenericReader<'a>) -> ImageResult<Box<dyn ImageDecoder + 'a>> {
|
||||||
let mut zip = ZipArchive::new(reader).map_err(|e| {
|
let mut zip = ZipArchive::new(reader).map_err(to_image_error)?;
|
||||||
ImageError::Decoding(DecodingError::new(
|
|
||||||
image::error::ImageFormatHint::PathExtension("kra".into()),
|
|
||||||
e,
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut reader = zip.by_name("mergedimage.png").map_err(|e| {
|
let mut reader = zip.by_name("mergedimage.png").map_err(to_image_error)?;
|
||||||
ImageError::Decoding(DecodingError::new(
|
|
||||||
image::error::ImageFormatHint::PathExtension("kra".into()),
|
|
||||||
e,
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// reading it all and wrapping it with a Cursor
|
// reading it all and wrapping it with a Cursor
|
||||||
// is the only way I know to give it Seek
|
// is the only way I know to give it Seek
|
||||||
|
|
@ -39,3 +29,12 @@ fn hook<'a>(reader: GenericReader<'a>) -> ImageResult<Box<dyn ImageDecoder + 'a>
|
||||||
|
|
||||||
Ok(Box::new(image_reader.into_decoder()?))
|
Ok(Box::new(image_reader.into_decoder()?))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_image_error(
|
||||||
|
e: impl Into<Box<dyn std::error::Error + std::marker::Send + Sync + 'static>>,
|
||||||
|
) -> ImageError {
|
||||||
|
ImageError::Decoding(DecodingError::new(
|
||||||
|
image::error::ImageFormatHint::PathExtension("kra".into()),
|
||||||
|
e,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue