move_it/work/
filter.rs

1use futures::{future, StreamExt}; // 0.3.1
2
3use super::Work;
4use crate::result::Result;
5
6impl<'a> Work<'a> {
7    pub fn include(self, re: impl Into<String>) -> Result<Work<'a>> {
8        let re = regex::Regex::new(&re.into())?;
9
10        self.add_work(move |elements| {
11            elements
12                .filter(move |element| {
13                    future::ready(
14                        re.is_match(element.get_file().path().as_path().to_str().unwrap()),
15                    )
16                })
17                .boxed()
18        })
19    }
20
21    pub fn exclude(self, re: impl Into<String>) -> Result<Work<'a>> {
22        let re = regex::Regex::new(&re.into())?;
23
24        self.add_work(move |elements| {
25            elements
26                .filter(move |element| {
27                    future::ready(
28                        !re.is_match(element.get_file().path().as_path().to_str().unwrap()),
29                    )
30                })
31                .boxed()
32        })
33    }
34}