git_glob/
lib.rs

1//! Provide glob [`Patterns`][Pattern] for matching against paths or anything else.
2//! ## Feature Flags
3#![cfg_attr(
4    feature = "document-features",
5    cfg_attr(doc, doc = ::document_features::document_features!())
6)]
7#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
8#![deny(missing_docs, rust_2018_idioms)]
9#![forbid(unsafe_code)]
10
11use bstr::BString;
12
13/// A glob pattern optimized for matching paths relative to a root directory.
14///
15/// For normal globbing, use [`wildmatch()`] instead.
16#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
17#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
18pub struct Pattern {
19    /// the actual pattern bytes
20    pub text: BString,
21    /// Additional information to help accelerate pattern matching.
22    pub mode: pattern::Mode,
23    /// The position in `text` with the first wildcard character, or `None` if there is no wildcard at all.
24    pub first_wildcard_pos: Option<usize>,
25}
26
27///
28pub mod pattern;
29
30///
31pub mod wildmatch;
32pub use wildmatch::function::wildmatch;
33
34mod parse;
35
36/// Create a [`Pattern`] by parsing `text` or return `None` if `text` is empty.
37///
38/// Note that
39pub fn parse(text: impl AsRef<[u8]>) -> Option<Pattern> {
40    Pattern::from_bytes(text.as_ref())
41}