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