use crate::Matcher;
use std::fmt::Debug;
pub fn contains(value: &str) -> Contains {
let regex = regex::Regex::new(value);
match regex {
Ok(regex) => Contains(regex),
Err(_) => panic!("Invalid regex pattern"),
}
}
pub struct Contains(regex::Regex);
impl<T> Matcher<T> for Contains
where
T: ToString + Debug,
{
fn matches(&self, value: &T) -> bool {
self.0
.is_match(&value.to_string())
}
fn description(&self) -> String {
format!("contains {:?}", self.0)
}
}