pub struct Pattern { /* private fields */ }Expand description
A pattern to match strings against.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn compile(pat: &str, opts: MatchOptions) -> Pattern
pub fn compile(pat: &str, opts: MatchOptions) -> Pattern
Compiles a pattern from a string, using shell-like syntax.
If you want to compile your own custom string format, see Pattern::from_iter.
Each of these can be toggled using MatchOptions.
- All characters prefixed with a backslash (
\) are interpreted literally. - (
MatchOptions::WILDCARDS) Asterisks (*s) are interpreted as wildcards: e.g.a*bis interpreted asa, a wildcard thenb. - (
MatchOptions::UNKNOWN_CHARS) Question marks (?s) are interpreted as optional characters.
Sourcepub fn compile_iter<T: IntoIterator<Item = char>>(
pat: T,
opts: MatchOptions,
) -> Pattern
pub fn compile_iter<T: IntoIterator<Item = char>>( pat: T, opts: MatchOptions, ) -> Pattern
The same as Pattern::compile, but with an iterator instead of a &str.
Trait Implementations§
Source§impl FromIterator<Chunk> for Pattern
impl FromIterator<Chunk> for Pattern
Source§fn from_iter<T: IntoIterator<Item = Chunk>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Chunk>>(iter: T) -> Self
Used to compile a Pattern from an iterator of Chunks.
Note that this allocates memory to store all the Chunks.
Example usage:
use patmatch::{Pattern, Chunk};
let chunk_vec = vec![Chunk::str("IMG_"), Chunk::Wildcard, Chunk::str(".png")];
let pat: Pattern = chunk_vec.into_iter().collect();
assert!(pat.matches("IMG_20170301.png"));
assert!(!pat.matches("stuff.png")); assert!(!pat.matches("IMG_20170302.jpeg"));Auto Trait Implementations§
impl Freeze for Pattern
impl !RefUnwindSafe for Pattern
impl !Send for Pattern
impl !Sync for Pattern
impl Unpin for Pattern
impl !UnwindSafe for Pattern
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more