diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index 9c7dd10..579265d 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -116,17 +116,11 @@ mod dynamic { infer::get_from_path(&path)? .map(|t| (t.matcher_type(), t.extension())) .map( - |(matcher, extension)| -> Result, OpenError> { + |(matcher, extension)| -> Result { Ok(match matcher { - Image => Some(DynamicBendable::Image(img::open(path)?)), - App | Archive if extension != "pdf" => Some(DynamicBendable::Binary({ - let mut buf = Vec::new(); - File::open(path)?.read_to_end(&mut buf)?; - buf - })), - App => unreachable!(), - Audio => Some(DynamicBendable::Sound(crate::snd::Audio::open(path)?)), - Archive if extension == "pdf" => Some(DynamicBendable::Archive( + Image => DynamicBendable::Image(img::open(path)?), + Audio => DynamicBendable::Sound(crate::snd::Audio::open(path)?), + Archive if extension == "pdf" => DynamicBendable::Archive( PdfDocument::try_from_data_bytes( File::open(path)? .bytes() @@ -135,39 +129,39 @@ mod dynamic { Default::default(), ) .map_err(OpenError::Pdf)?, - )), + ), Archive => { let document_type = DocumentType::from_extension(extension) .ok_or(ShivaUnknownExtensionError) .map_err(ShivaError::UnknownExtension)?; - Some(DynamicBendable::Doc(ShivaDocument::new( + DynamicBendable::Doc(ShivaDocument::new( Document::parse( &bytes::Bytes::from(std::fs::read(path)?), document_type, ) .map_err(ShivaError::Anyhow)?, document_type, - ))) + )) } Book => todo!(), Doc => todo!(), Font => todo!(), - Text => Some(DynamicBendable::Text( - crate::txt::Text::try_from_data_bytes( - File::open(path)? - .bytes() - .collect::>()?, - (), - Default::default(), - )?, - )), - Video => todo!(), - Custom => None, + Text => DynamicBendable::Text(crate::txt::Text::try_from_data_bytes( + File::open(path)? + .bytes() + .collect::>()?, + (), + Default::default(), + )?), + _ => DynamicBendable::Binary({ + let mut buf = Vec::new(); + File::open(path)?.read_to_end(&mut buf)?; + buf + }), }) }, ) .transpose() - .map(|opt| -> Option { opt? }) } }