use std::ops::Deref;
use std::{fmt, hash};
pub fn escape(s: &str) -> String {
let mut escaped = String::with_capacity(s.len());
for c in s.chars() {
match c {
'?' | '*' | '[' | ']' => {
escaped.push('[');
escaped.push(c);
escaped.push(']');
}
c => {
escaped.push(c);
}
}
}
escaped
}
#[derive(Clone, Debug)]
pub struct GlobMatcher(globset::GlobMatcher);
impl PartialEq for GlobMatcher {
fn eq(&self, other: &GlobMatcher) -> bool {
self.glob() == other.glob()
}
}
impl Eq for GlobMatcher {}
impl hash::Hash for GlobMatcher {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.glob().hash(state);
}
}
impl fmt::Display for GlobMatcher {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.glob().fmt(f)
}
}
impl Deref for GlobMatcher {
type Target = globset::GlobMatcher;
fn deref(&self) -> &globset::GlobMatcher {
&self.0
}
}
impl From<GlobMatcher> for globset::GlobMatcher {
fn from(outer: GlobMatcher) -> Self {
outer.0
}
}
impl From<globset::GlobMatcher> for GlobMatcher {
fn from(inner: globset::GlobMatcher) -> Self {
Self(inner)
}
}