pub struct PathMatch { /* private fields */ }Expand description
Matches against a path
Implementations§
Source§impl PathMatch
impl PathMatch
Sourcepub fn from_pattern(pattern: &str, separator: &str) -> Result<PathMatch, Error>
pub fn from_pattern(pattern: &str, separator: &str) -> Result<PathMatch, Error>
Constructs a PathMatch for a single pattern.
The pattern must use the forward slash as a separator. The following restrictions apply:
- Each component must either be a literal name or can contain a single asterisk (representing a wildcard) with an optional literal prefix and suffix.
?is not supported.- The pattern must not contain parent traversals (
..) but.is supported. - No escaping of special characters is supported.
Construction will return an error if parent traverals are present or a component contains multiple wildcard characters.
The supplied separator is used when parsing the supplied paths. The idea is that the patterns you use are specified in an OS-independent manner so they can be compile-time constant, but the separator is supplied at run-time to allow adaptation to OS.
Sourcepub fn matches<P: AsRef<str>>(&self, path: P) -> bool
pub fn matches<P: AsRef<str>>(&self, path: P) -> bool
Returns true if the specified string matches the pattern, false
otherwise. Unlike patterns, paths may contain .., but if the parent
traversal cannot be normalized out, no matches can occur.
Sourcepub fn matches_prefix<P: AsRef<str>>(&self, path: P) -> bool
pub fn matches_prefix<P: AsRef<str>>(&self, path: P) -> bool
Returns true if the specified string forms a prefix path of one of the
patterns matches.
The prefix must consist of full components. e.g. first/second is a
prefix of first/second/third, but first/sec is not.