#matcher

path-matchers

A collection of path matchers

3 stable releases

1.0.2 Apr 19, 2021
1.0.1 Dec 12, 2020

#812 in Filesystem

Download history 2799/week @ 2024-12-08 2516/week @ 2024-12-15 1790/week @ 2024-12-22 2168/week @ 2024-12-29 3486/week @ 2025-01-05 4006/week @ 2025-01-12 3675/week @ 2025-01-19 4605/week @ 2025-01-26 3898/week @ 2025-02-02 3719/week @ 2025-02-09 9293/week @ 2025-02-16 6338/week @ 2025-02-23 6029/week @ 2025-03-02 7857/week @ 2025-03-09 4781/week @ 2025-03-16 5489/week @ 2025-03-23

24,747 downloads per month
Used in 29 crates (via change-detection)

Unlicense OR MIT

20KB
442 lines

A collection of useful path matchers

Dual-licensed under MIT or the UNLICENSE.

Features

  • Matches path with another path or glob expression.
  • Allows to combine multiple path matchers.

Usage

Add dependency to Cargo.toml:

[dependencies]
path-matchers = "1.0"

Use it where appropriate:

use std::path::PathBuf;
use path_matchers::{any, glob, PathMatcher, PathMatcherExt};

fn main() {
    let path1 = PathBuf::from("images/big/best.png");
    let path2 = PathBuf::from("images/small/32x32/best.jpg");

    // check both paths matches `images/**/best.*`
    let all_best_images = glob("images/**/best.*").unwrap();

    assert!(all_best_images.matches(&path1));
    assert!(all_best_images.matches(&path2));

    let all_jpgs = glob("images/**/*.jpg").unwrap();
    assert!(!all_jpgs.matches(&path1));
    assert!(all_jpgs.matches(&path2));

    let all_pngs = glob("images/**/*.png").unwrap();
    assert!(all_pngs.matches(&path1));
    assert!(!all_pngs.matches(&path2));

    // now we can combine two matchers to match both jpgs and pngs
    let all_pics = all_jpgs.or(all_pngs);
    assert!(all_pics.matches(&path1));
    assert!(all_pics.matches(&path2));

    // you can also use macro for the same
    let all_jpgs = glob("images/**/*.jpg").unwrap();
    let all_pngs = glob("images/**/*.png").unwrap();
    let all_pics = any!(all_jpgs, all_pngs);
    assert!(all_pics.matches(&path1));
    assert!(all_pics.matches(&path2));
}

Dependencies

~50KB