pub struct GlobPattern { /* private fields */ }Expand description
One GOPRIVATE/GONOPROXY-style glob pattern (FR-007).
Matched against a module path per Go’s own GlobsMatchPath + path.Match semantics (go help goprivate): only the pattern’s own number of /-separated elements is compared
against the module path’s leading elements, then matched with shell-glob syntax (*, ?,
[...]/[^...]) that never crosses a /.
Compiles its pattern once at construction into a token sequence, matched by the iterative
tokens_match rather than naive recursive backtracking — a naive backtracking
implementation is exponential (O(2^n)) on an adversarial pattern like many consecutive
*s against a non-matching text (spec 034 perf review finding: 15 stars took ~19s, 20
timed out); the token/iterative-pointer approach used here is O(pattern length * matched text length), the same bound the classic “wildcard matching” two-pointer algorithm gives.
Implementations§
Source§impl GlobPattern
impl GlobPattern
Sourcepub fn new(raw: &str) -> Self
pub fn new(raw: &str) -> Self
Wraps and compiles raw — no validation surfaced to the caller, matching
path.Match’s own behavior (a malformed or oversized pattern simply never matches, per
Self::tokens’s doc). Rejection paths log a tracing::warn!: an oversized pattern
(spec 034 follow-up F6, issue #559) here, and a malformed pattern (unterminated [
character class, issue #568) inside compile_glob — both invalidate the whole pattern.
A reversed [lo-hi] range (issue #570) also logs a tracing::warn! inside
compile_glob, but — matching Go’s own path.Match — does not invalidate the
pattern; see Self::tokens’s doc. Unlike a malformed GOPROXY hop, a GOPRIVATE
pattern that never matches fails open on confidentiality (the module it should
have hidden from the public proxy routes there instead), so these cases must be
visible rather than silent.
Sourcepub fn matches(&self, module_path: &str) -> bool
pub fn matches(&self, module_path: &str) -> bool
Whether module_path matches this pattern (FR-008).
§Examples
use deps_go::config::GlobPattern;
let pattern = GlobPattern::new("git.mycorp.example/*");
assert!(pattern.matches("git.mycorp.example/internal/auth"));
assert!(!pattern.matches("github.com/other/repo"));Trait Implementations§
Source§impl Clone for GlobPattern
impl Clone for GlobPattern
Source§fn clone(&self) -> GlobPattern
fn clone(&self) -> GlobPattern
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GlobPattern
impl Debug for GlobPattern
impl Eq for GlobPattern
Source§impl PartialEq for GlobPattern
impl PartialEq for GlobPattern
Source§fn eq(&self, other: &GlobPattern) -> bool
fn eq(&self, other: &GlobPattern) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for GlobPattern
Auto Trait Implementations§
impl Freeze for GlobPattern
impl RefUnwindSafe for GlobPattern
impl Send for GlobPattern
impl Sync for GlobPattern
impl Unpin for GlobPattern
impl UnsafeUnpin for GlobPattern
impl UnwindSafe for GlobPattern
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.