pub fn any<'t, I>(patterns: I) -> Result<Any<'t>, BuildError>where
I: IntoIterator,
I::Item: Combine<'t>,
Expand description
Constructs a combinator that matches if any of its input Pattern
s match.
This function accepts an IntoIterator
with items that implement Combine
, such as
Glob
and &str
. The output Any
implements Pattern
by matching its component
Pattern
s. Any
is often more ergonomic and efficient than matching individually against
multiple Pattern
s.
Any
groups all captures and therefore only exposes the complete text of a match. It is not
possible to index a particular capturing token in the component patterns. Combinators only
support logical matching and cannot be used to semantically match (walk) a directory tree.
Examples
To match a path against multiple patterns, the patterns can first be combined into an Any
.
use wax::{Glob, Pattern};
let any = wax::any([
"src/**/*.rs",
"tests/**/*.rs",
"doc/**/*.md",
"pkg/**/PKGBUILD",
])
.unwrap();
assert!(any.is_match("src/lib.rs"));
Glob
s and other compiled Pattern
s can also be composed into an Any
.
use wax::{Glob, Pattern};
let red = Glob::new("**/red/**/*.txt").unwrap();
let blue = Glob::new("**/*blue*.txt").unwrap();
assert!(wax::any([red, blue]).unwrap().is_match("red/potion.txt"));
This function can only combine patterns of the same type, but intermediate combinators can be used to combine different types into a single combinator.
use wax::{Glob, Pattern};
let glob = Glob::new("**/*.txt")?;
// ...
#[rustfmt::skip]
let any = wax::any([
wax::any([glob])?,
wax::any([
"**/*.pdf",
"**/*.tex",
])?,
])?;
assert!(any.is_match("doc/lattice.tex"));
Errors
Returns an error if any of the inputs fail to build. If the inputs are a compiled Pattern
type such as Glob
, then this only occurs if the compiled program is too large.