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()
(orto_uppercase()
) on both pattern and target string. Display
implementation prints parsed pattern, not the original one.- Implementations of
From<&'a str>
andFrom<&'a String>
always borrow the source string. - Implementations of
FromStr
andFrom<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§
source§impl<'a> Ord for Glob<'a>
impl<'a> Ord for Glob<'a>
source§impl<'a> PartialEq<Glob<'a>> for Glob<'a>
impl<'a> PartialEq<Glob<'a>> for Glob<'a>
source§impl<'a> PartialOrd<Glob<'a>> for Glob<'a>
impl<'a> PartialOrd<Glob<'a>> for Glob<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more