Struct Pattern
struct Pattern { ... }
A compiled Unix shell style pattern.
-
?matches any single character. -
*matches any (possibly empty) sequence of characters. -
**matches the current directory and arbitrary subdirectories. To match files in arbitrary subdirectories, use**/*.This sequence must form a single path component, so both
**aandb**are invalid and will result in an error. A sequence of more than two consecutive*characters is also invalid. -
[...]matches any character inside the brackets. Character sequences can also specify ranges of characters, as ordered by Unicode, so e.g.[0-9]specifies any character between 0 and 9 inclusive. An unclosed bracket is invalid. -
[!...]is the negation of[...], i.e. it matches any characters not in the brackets. -
The metacharacters
?,*,[,]can be matched by using brackets (e.g.[?]). When a]occurs immediately following[or[!then it is interpreted as being part of, rather then ending, the character set, so]and NOT]can be matched by[]]and[!]]respectively. The-character can be specified inside a character sequence pattern by placing it at the start or the end, e.g.[abc-].
Implementations
impl Pattern
fn new(pattern: &str) -> Result<Self, PatternError>This function compiles Unix shell style patterns.
An invalid glob pattern will yield a
PatternError.fn escape(s: &str) -> StringEscape metacharacters within the given string by surrounding them in brackets. The resulting string will, when compiled into a
Pattern, match the input string and nothing else.fn matches(self: &Self, str: &str) -> boolReturn if the given
strmatches thisPatternusing the default match options (i.e.MatchOptions::new()).Examples
use Pattern; assert!; assert!; assert!;fn matches_path(self: &Self, path: &Path) -> boolReturn if the given
Path, when converted to astr, matches thisPatternusing the default match options (i.e.MatchOptions::new()).fn matches_with(self: &Self, str: &str, options: MatchOptions) -> boolReturn if the given
strmatches thisPatternusing the specified match options.fn matches_path_with(self: &Self, path: &Path, options: MatchOptions) -> boolReturn if the given
Path, when converted to astr, matches thisPatternusing the specified match options.fn as_str(self: &Self) -> &strAccess the original glob pattern.
impl Clone for Pattern
fn clone(self: &Self) -> Pattern
impl Debug for Pattern
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for Pattern
fn default() -> Pattern
impl Display for Pattern
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Eq for Pattern
impl Freeze for Pattern
impl FromStr for Pattern
fn from_str(s: &str) -> Result<Self, PatternError>
impl Hash for Pattern
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for Pattern
fn cmp(self: &Self, other: &Pattern) -> $crate::cmp::Ordering
impl PartialEq for Pattern
fn eq(self: &Self, other: &Pattern) -> bool
impl PartialOrd for Pattern
fn partial_cmp(self: &Self, other: &Pattern) -> $crate::option::Option<$crate::cmp::Ordering>
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl StructuralPartialEq for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
impl<T> Any for Pattern
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Pattern
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Pattern
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Pattern
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Pattern
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Pattern
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> ToString for Pattern
fn to_string(self: &Self) -> String
impl<T, U> Into for Pattern
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Pattern
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Pattern
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>