Struct Pattern

struct Pattern { ... }

A compiled Unix shell style pattern.

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) -> String

Escape 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) -> bool

Return if the given str matches this Pattern using the default match options (i.e. MatchOptions::new()).

Examples

use glob::Pattern;

assert!(Pattern::new("c?t").unwrap().matches("cat"));
assert!(Pattern::new("k[!e]tteh").unwrap().matches("kitteh"));
assert!(Pattern::new("d*g").unwrap().matches("doog"));
fn matches_path(self: &Self, path: &Path) -> bool

Return if the given Path, when converted to a str, matches this Pattern using the default match options (i.e. MatchOptions::new()).

fn matches_with(self: &Self, str: &str, options: MatchOptions) -> bool

Return if the given str matches this Pattern using the specified match options.

fn matches_path_with(self: &Self, path: &Path, options: MatchOptions) -> bool

Return if the given Path, when converted to a str, matches this Pattern using the specified match options.

fn as_str(self: &Self) -> &str

Access 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) -> T

Returns the argument unchanged.

impl<T> ToOwned for Pattern

fn to_owned(self: &Self) -> T
fn 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) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>