cleanup generic open function
This commit is contained in:
parent
3527c0a2af
commit
bcce055d4c
1 changed files with 21 additions and 19 deletions
|
@ -40,25 +40,27 @@ pub mod dynamic {
|
|||
|
||||
pub fn open<P: AsRef<Path>>(path: P) -> Result<Option<DynamicBendable>, OpenError> {
|
||||
use MatcherType::*;
|
||||
if let Some(matcher) = infer::get_from_path(&path)?.map(|t| t.matcher_type()) {
|
||||
Ok(Some(match matcher {
|
||||
Image => DynamicBendable::Image(img::open(path)?),
|
||||
App | Archive => DynamicBendable::Binary({
|
||||
let mut buf = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buf)?;
|
||||
buf
|
||||
}),
|
||||
Audio => todo!(),
|
||||
Book => todo!(),
|
||||
Doc => todo!(),
|
||||
Font => todo!(),
|
||||
Text => todo!(),
|
||||
Video => todo!(),
|
||||
Custom => unimplemented!("I don't even know what this is!"),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
infer::get_from_path(&path)?
|
||||
.map(|t| t.matcher_type())
|
||||
.map(|matcher| -> Result<Option<DynamicBendable>, OpenError> {
|
||||
Ok(match matcher {
|
||||
Image => Some(DynamicBendable::Image(img::open(path)?)),
|
||||
App | Archive => Some(DynamicBendable::Binary({
|
||||
let mut buf = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buf)?;
|
||||
buf
|
||||
})),
|
||||
Audio => todo!(),
|
||||
Book => todo!(),
|
||||
Doc => todo!(),
|
||||
Font => todo!(),
|
||||
Text => todo!(),
|
||||
Video => todo!(),
|
||||
Custom => None,
|
||||
})
|
||||
})
|
||||
.transpose()
|
||||
.map(|opt| -> Option<DynamicBendable> { opt? })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue