pub fn any<'t, P, I>(
patterns: I
) -> Result<Any<'t>, <I::Item as TryInto<P>>::Error> where
P: Pattern<'t>,
I: IntoIterator,
I::Item: TryInto<P>,
Expand description
Combinator that emits a Pattern
that matches if any of its input
Pattern
s match.
This function accepts an IntoIterator
with items that can be converted
into a Pattern
type. The output Any
implements Pattern
by
matching any of its component Pattern
s. Any
is often more ergonomic
and efficient than matching against multiple Glob
s or other
Pattern
s. Moreover, because any
accepts any type that can be converted
into a Pattern
, it is possible to combine opaque patterns from foreign
code.
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.
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::<Glob, _>([
"src/**/*.rs",
"tests/**/*.rs",
"doc/**/*.md",
"pkg/**/PKGBUILD",
])
.unwrap();
if any.is_match("src/lib.rs") { /* ... */ }
Opaque patterns can also be combined, such as Glob
s from foreign code.
use wax::{Glob, GlobError, Pattern};
fn unknown() -> Result<Glob<'static>, GlobError<'static>> {
/* ... */
}
let known = Glob::new("**/*.txt").unwrap();
let unknown = unknown().unwrap();
if wax::any::<Glob, _>([known, unknown])
.unwrap()
.is_match("README.md")
{ /* ... */ }
Errors
Returns an error if any of the inputs could not be converted into the target
Pattern
type P
.