Struct sub_strs::Glob[][src]

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

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);
}

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.