Outsource globlist -> Vec<FileID> transformation code snippet

This commit is contained in:
Matthias Beyer 2015-12-04 22:53:31 +01:00
parent dac4911ea2
commit 6473b743a3

View file

@ -59,10 +59,7 @@ impl StorageBackend {
glob(&globstr[..]) glob(&globstr[..])
.and_then(|globlist| { .and_then(|globlist| {
debug!("Iterating over globlist"); debug!("Iterating over globlist");
Ok(globlist.filter_map(Result::ok) Ok(globlist_to_file_id_vec(globlist).into_iter())
.map(|pbuf| FileID::from(&pbuf))
.collect::<Vec<FileID>>()
.into_iter())
}) })
.map_err(|e| { .map_err(|e| {
debug!("glob() returned error: {:?}", e); debug!("glob() returned error: {:?}", e);
@ -198,8 +195,7 @@ impl StorageBackend {
let globstr = self.prefix_of_files_for_module(m) + "*" + ".imag"; let globstr = self.prefix_of_files_for_module(m) + "*" + ".imag";
glob(&globstr[..]).map(|globlist| { glob(&globstr[..]).map(|globlist| {
let mut vec = globlist.filter_map(Result::ok) let mut vec = globlist_to_file_id_vec(globlist).into_iter()
.map(|pbuf| FileID::from(&pbuf))
.filter_map(|id| self.get_file_by_id(m, &id, p)) .filter_map(|id| self.get_file_by_id(m, &id, p))
.collect::<Vec<File>>(); .collect::<Vec<File>>();
vec.reverse(); vec.reverse();
@ -326,3 +322,9 @@ fn write_with_parser<'a, HP>(f: &File, p: &Parser<HP>) -> Result<String, Storage
Err(serr) Err(serr)
}) })
} }
fn globlist_to_file_id_vec(globlist: Paths) -> Vec<FileID> {
globlist.filter_map(Result::ok)
.map(|pbuf| FileID::from(&pbuf))
.collect::<Vec<FileID>>()
}