1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate glob;
use std::path::Path;
use glob::{glob_with,Paths,PatternError,MatchOptions};
pub trait Glob {
fn glob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError>;
fn glob(&self, pattern: &str) -> Result<Paths, PatternError> {
self.glob_with(pattern, &MatchOptions::new())
}
fn rglob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError> {
self.glob_with(&format!("**/{}", pattern), options)
}
fn rglob(&self, pattern: &str) -> Result<Paths, PatternError> {
self.rglob_with(pattern, &MatchOptions::new())
}
}
impl<P: AsRef<Path>> Glob for P {
fn glob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError> {
glob_with(self.as_ref().join(pattern).to_str().unwrap(), options)
}
}