pub fn any<'t, I>(patterns: I) -> Result<Any<'t>, BuildError>where
I: IntoIterator,
I::Item: Pattern<'t>,Expand description
Constructs a combinator that matches if any of its input Patterns match.
This function accepts an IntoIterator with items that implement Pattern, such as
Glob and &str. The output Any implements Program by matching its component
Programs. Any is often more ergonomic and efficient than matching individually against
multiple Programs.
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, Program};
let any = wax::any([
"src/**/*.rs",
"tests/**/*.rs",
"doc/**/*.md",
"pkg/**/PKGBUILD",
])
.unwrap();
assert!(any.is_match("src/lib.rs"));Globs and other compiled Programs can also be composed into an Any.
use wax::{Glob, Program};
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, Program};
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 Program
type such as Glob, then this only occurs if the compiled program is too large.