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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#[cfg(feature = "regex")]
extern crate regex;
#[cfg(feature = "wildmatch")]
extern crate wildmatch;
mod error;
mod filters;
pub(crate) mod finders;
mod utils;
use std::path::PathBuf;
pub use error::{BoxError, Error, Result};
pub use filters::{FilesFilter, MultipleFilesFilter, OneFileFilter};
#[derive(Debug, Clone)]
pub enum FileNamed {
Exact(String),
Any(Vec<String>),
#[cfg(feature = "regex")]
Regex(String),
#[cfg(feature = "wildmatch")]
Wildmatch(String),
}
#[derive(Debug, Clone)]
pub enum FilesNamed {
Exact(String),
Any(Vec<String>),
#[cfg(feature = "regex")]
Regex(String),
#[cfg(feature = "wildmatch")]
Wildmatch(String),
}
impl FileNamed {
pub fn within(&self, directory: impl Into<PathBuf>) -> OneFileFilter {
OneFileFilter::new(self.clone(), directory)
}
pub fn exact(name: impl Into<String>) -> Self {
Self::Exact(name.into())
}
pub fn any(names: Vec<impl Into<String>>) -> Self {
Self::Any(names.into_iter().map(|name| name.into()).collect())
}
#[cfg(feature = "regex")]
pub fn regex(pattern: impl Into<String>) -> Self {
Self::Regex(pattern.into())
}
#[cfg(feature = "wildmatch")]
pub fn wildmatch(pattern: impl Into<String>) -> Self {
Self::Wildmatch(pattern.into())
}
}
impl FilesNamed {
pub fn within(&self, directory: impl Into<PathBuf>) -> MultipleFilesFilter {
MultipleFilesFilter::new(self.clone(), directory)
}
pub fn exact(name: impl Into<String>) -> Self {
Self::Exact(name.into())
}
pub fn any(names: Vec<impl Into<String>>) -> Self {
Self::Any(names.into_iter().map(|name| name.into()).collect())
}
#[cfg(feature = "regex")]
pub fn regex(pattern: impl Into<String>) -> Self {
Self::Regex(pattern.into())
}
#[cfg(feature = "wildmatch")]
pub fn wildmatch(pattern: impl Into<String>) -> Self {
Self::Wildmatch(pattern.into())
}
}