path_glob/
lib.rs

1//! Glob methods for [`Path`](https://doc.rust-lang.org/std/path/struct.Path.html) and friends.
2//! 
3//! * [GitHub repo](https://github.com/flying-sheep/path-glob)
4
5extern crate glob;
6
7use std::path::Path;
8
9use glob::{glob_with,Paths,PatternError,MatchOptions};
10
11/// A trait providing glob methods.
12/// 
13/// The idea is “glob starting from here”
14pub trait Glob {
15	/// Glob here with explicit options
16	fn glob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError>;
17	
18	/// Glob here with default options
19	fn glob(&self, pattern: &str) -> Result<Paths, PatternError> {
20		self.glob_with(pattern, &MatchOptions::new())
21	}
22	
23	/// Glob inside of here with explicit options (`<here>/**/<pattern>`)
24	fn rglob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError> {
25		self.glob_with(&format!("**/{}", pattern), options)
26	}
27	
28	/// Glob inside of here with default options (`<here>/**/<pattern>`)
29	fn rglob(&self, pattern: &str) -> Result<Paths, PatternError> {
30		self.rglob_with(pattern, &MatchOptions::new())
31	}
32}
33
34impl<P: AsRef<Path>> Glob for P {
35	fn glob_with(&self, pattern: &str, options: &MatchOptions) -> Result<Paths, PatternError> {
36		glob_with(self.as_ref().join(pattern).to_str().unwrap(), options)
37	}
38}