Struct patmatch::Pattern [−][src]
A pattern to match strings against.
Implementations
impl Pattern
[src]
pub fn compile(pat: &str, opts: MatchOptions) -> Pattern
[src]
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*b
is interpreted asa
, a wildcard thenb
. - (
MatchOptions::UNKNOWN_CHARS
) Question marks (?
s) are interpreted as optional characters.
pub fn compile_iter<T: IntoIterator<Item = char>>(
pat: T,
opts: MatchOptions
) -> Pattern
[src]
pat: T,
opts: MatchOptions
) -> Pattern
The same as Pattern::compile
, but with an iterator instead of a &str
.
pub fn matches(&self, string: &str) -> bool
[src]
Checks if string
matches the pattern.
The pattern is checked for a match “perfectly”,
i.e. if it is possible to match by choosing all of the matches optimally,
it will do so.
This optimizes matching checks if not all features are used.
Trait Implementations
impl Clone for Pattern
[src]
impl Debug for Pattern
[src]
impl FromIterator<Chunk> for Pattern
[src]
fn from_iter<T: IntoIterator<Item = Chunk>>(iter: T) -> Self
[src]
Used to compile a Pattern
from an iterator of Chunk
s.
Note that this allocates memory to store all the Chunk
s.
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 !RefUnwindSafe for Pattern
impl !Send for Pattern
impl !Sync for Pattern
impl Unpin for Pattern
impl !UnwindSafe for Pattern
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
pub fn __clone_box(&self, Private) -> *mut ()
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,