[][src]Struct sub_strs::Glob

pub struct Glob<'a> { /* fields omitted */ }

Glob

This struct is used to find matches from a pattern string against some string.

The pattern string supports 2 special characters: * and ?:

  • *: matches any characters or nothing at all.
  • ?: matches one single character.

Notes

  • The idea is inspired by https://en.wikipedia.org/wiki/Glob_%28programming%29, but this is not an implementation of that or any other specifications.
  • Matches are case sensitive. If you want to ignore case, consider using to_lowercase() (or to_uppercase()) on both pattern and target string.
  • Display implementation prints parsed pattern, not the original one.
  • Implementations of From<&'a str> and From<&'a String> always borrow the source string.
  • Implementations of FromStr and From<String> will clone the source string.

Examples

use sub_strs::Glob;

let g = Glob::from("*r?st.rs");
for s in &["rust.rs", "rEst.rs", "it's rust.rs"] {
    assert!(g.matches(s));
}
for s in &["it's not Rust", "rest", "rust!.rs"] {
    assert!(g.matches(s) == false);
}

Methods

impl<'a> Glob<'a>[src]

pub fn matches<S>(&self, s: S) -> bool where
    S: AsRef<str>, 
[src]

Trait Implementations

impl<'a> PartialEq<Glob<'a>> for Glob<'a>[src]

impl<'a> Eq for Glob<'a>[src]

impl<'a> From<&'a str> for Glob<'a>[src]

impl<'a> From<&'a String> for Glob<'a>[src]

impl<'_> From<String> for Glob<'_>[src]

impl<'a> From<Cow<'a, str>> for Glob<'a>[src]

impl<'a> Hash for Glob<'a>[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<'a> Debug for Glob<'a>[src]

impl<'_> Display for Glob<'_>[src]

impl<'_> FromStr for Glob<'_>[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl<'a> Send for Glob<'a>

impl<'a> Unpin for Glob<'a>

impl<'a> Sync for Glob<'a>

impl<'a> UnwindSafe for Glob<'a>

impl<'a> RefUnwindSafe for Glob<'a>

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]