pub struct Glob<'a> { /* private fields */ }
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

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.