From 80563cb340e19c2f29cc638242a76b03c30423dc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 5 Dec 2015 11:05:50 +0100 Subject: [PATCH] Move tag filtering to sub-function --- src/module/bm/commands.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/module/bm/commands.rs b/src/module/bm/commands.rs index ad8f358f..edc4f3d6 100644 --- a/src/module/bm/commands.rs +++ b/src/module/bm/commands.rs @@ -123,6 +123,17 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module, env: &CommandEnv) -> Result>, ModuleError> { + fn check_tags(tags: &Vec, file: &File) -> bool { + if tags.len() != 0 { + debug!("Checking tags of: {:?}", file.id()); + get_tags_from_header(&file.header()) + .iter() + .any(|t| tags.contains(t)) + } else { + true + } + } + let parser = Parser::new(JsonHeaderParser::new(None)); let tags = get_tags(env.rt, env.matches); debug!("Tags: {:?}", tags); @@ -130,13 +141,7 @@ fn get_filtered_files_from_backend<'a>(module: &'a Module, .map(|files| { let f = files.filter(|file| { debug!("Backend returns file: {:?}", file); - if tags.len() != 0 { - debug!("Checking tags of: {:?}", file.id()); - get_tags_from_header(&file.header()).iter() - .any(|t| tags.contains(t)) - } else { - true - } + check_tags(&tags, file) }).filter(|file| { debug!("Checking matches of: {:?}", file.id()); get_matcher(env.rt, env.matches)