3 个稳定版本

1.0.2 2021 年 4 月 19 日
1.0.1 2020 年 12 月 12 日

#694文件系统

Download history 2830/week @ 2024-03-14 3226/week @ 2024-03-21 2926/week @ 2024-03-28 2824/week @ 2024-04-04 2611/week @ 2024-04-11 2780/week @ 2024-04-18 2717/week @ 2024-04-25 2610/week @ 2024-05-02 2303/week @ 2024-05-09 2501/week @ 2024-05-16 2273/week @ 2024-05-23 2274/week @ 2024-05-30 2213/week @ 2024-06-06 2256/week @ 2024-06-13 2400/week @ 2024-06-20 2093/week @ 2024-06-27

9,284 每月下载量
用于 29 个Crates (直接使用2个)

Unlicense 或 MIT

20KB
442

一组有用的路径匹配器

双许可下 MITUNLICENSE

功能

  • 匹配另一个路径或glob表达式与路径。
  • 允许组合多个路径匹配器。

使用方法

将依赖项添加到 Cargo.toml

[dependencies]
path-matchers = "1.0"

在适当的地方使用

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

依赖项

~48KB