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> {
|
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? })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue