1use std::fmt;
2
3#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FilterOp {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "FilterOp",
"inner", &&self.inner)
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for FilterOp {
#[inline]
fn clone(&self) -> FilterOp {
FilterOp { inner: ::core::clone::Clone::clone(&self.inner) }
}
}Clone)]
4pub(crate) struct FilterOp {
5 #[cfg(feature = "regex")]
6 inner: regex::Regex,
7 #[cfg(not(feature = "regex"))]
8 inner: String,
9}
10
11#[cfg(feature = "regex")]
12impl FilterOp {
13 pub(crate) fn new(spec: &str) -> Result<Self, String> {
14 match regex::Regex::new(spec) {
15 Ok(r) => Ok(Self { inner: r }),
16 Err(e) => Err(e.to_string()),
17 }
18 }
19
20 pub(crate) fn is_match(&self, s: &str) -> bool {
21 self.inner.is_match(s)
22 }
23}
24
25#[cfg(not(feature = "regex"))]
26impl FilterOp {
27 pub fn new(spec: &str) -> Result<Self, String> {
28 Ok(Self {
29 inner: spec.to_string(),
30 })
31 }
32
33 pub fn is_match(&self, s: &str) -> bool {
34 s.contains(&self.inner)
35 }
36}
37
38impl fmt::Display for FilterOp {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 self.inner.fmt(f)
41 }
42}