pub struct GlobMap<T> { /* private fields */ }Expand description
A map from glob patterns to values.
GlobMap<T> pairs each glob pattern with an associated value of type T.
Lookups return the value associated with the first (lowest-index) matching
pattern.
Internally uses the same optimized strategy-based dispatch as GlobSet
(extension hash, literal, prefix, suffix, Aho-Corasick pre-filter).
§Example
use glob_set::{Glob, GlobMapBuilder};
let mut builder = GlobMapBuilder::new();
builder.insert(Glob::new("*.rs").unwrap(), "rust");
builder.insert(Glob::new("*.toml").unwrap(), "toml");
let map = builder.build().unwrap();
assert_eq!(map.get("foo.rs"), Some(&"rust"));
assert_eq!(map.get("Cargo.toml"), Some(&"toml"));
assert_eq!(map.get("foo.js"), None);Implementations§
Source§impl<T> GlobMap<T>
impl<T> GlobMap<T>
Sourcepub fn get(&self, path: impl AsRef<str>) -> Option<&T>
pub fn get(&self, path: impl AsRef<str>) -> Option<&T>
Return the value associated with the first matching pattern, or None.
Sourcepub fn get_candidate(&self, candidate: &Candidate<'_>) -> Option<&T>
pub fn get_candidate(&self, candidate: &Candidate<'_>) -> Option<&T>
Return the value associated with the first matching pattern for a candidate, or None.
Sourcepub fn get_matches(&self, path: impl AsRef<str>) -> Vec<&T>
pub fn get_matches(&self, path: impl AsRef<str>) -> Vec<&T>
Return references to all values whose patterns match the given path.
Values are returned in match order (same order as GlobSet::matches).
Sourcepub fn get_matches_candidate(&self, candidate: &Candidate<'_>) -> Vec<&T>
pub fn get_matches_candidate(&self, candidate: &Candidate<'_>) -> Vec<&T>
Return references to all values whose patterns match the given candidate.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for GlobMap<T>
impl<T> RefUnwindSafe for GlobMap<T>where
T: RefUnwindSafe,
impl<T> Send for GlobMap<T>where
T: Send,
impl<T> Sync for GlobMap<T>where
T: Sync,
impl<T> Unpin for GlobMap<T>where
T: Unpin,
impl<T> UnsafeUnpin for GlobMap<T>
impl<T> UnwindSafe for GlobMap<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more