Struct patmatch::Pattern[][src]

pub struct Pattern { /* fields omitted */ }

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 as a, a wildcard then b.
  • (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]

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 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 !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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.