cleanup generic open function

This commit is contained in:
Breval Ferrari 2025-03-06 12:55:59 -05:00
parent 3527c0a2af
commit bcce055d4c
Signed by: breval
GPG key ID: 6AEDB3B098E5B3DD

View file

@ -40,25 +40,27 @@ pub mod dynamic {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Option<DynamicBendable>, OpenError> { pub fn open<P: AsRef<Path>>(path: P) -> Result<Option<DynamicBendable>, OpenError> {
use MatcherType::*; use MatcherType::*;
if let Some(matcher) = infer::get_from_path(&path)?.map(|t| t.matcher_type()) { infer::get_from_path(&path)?
Ok(Some(match matcher { .map(|t| t.matcher_type())
Image => DynamicBendable::Image(img::open(path)?), .map(|matcher| -> Result<Option<DynamicBendable>, OpenError> {
App | Archive => DynamicBendable::Binary({ Ok(match matcher {
let mut buf = Vec::new(); Image => Some(DynamicBendable::Image(img::open(path)?)),
File::open(path)?.read_to_end(&mut buf)?; App | Archive => Some(DynamicBendable::Binary({
buf let mut buf = Vec::new();
}), File::open(path)?.read_to_end(&mut buf)?;
Audio => todo!(), buf
Book => todo!(), })),
Doc => todo!(), Audio => todo!(),
Font => todo!(), Book => todo!(),
Text => todo!(), Doc => todo!(),
Video => todo!(), Font => todo!(),
Custom => unimplemented!("I don't even know what this is!"), Text => todo!(),
})) Video => todo!(),
} else { Custom => None,
Ok(None) })
} })
.transpose()
.map(|opt| -> Option<DynamicBendable> { opt? })
} }
} }