use crate::util::ShouldSkip;
#[derive(Debug, Clone, Serialize, PartialEq)]
#[serde(untagged)]
pub enum TermsExclude {
Regex(String),
Exact(Vec<String>),
}
impl ShouldSkip for TermsExclude {
fn should_skip(&self) -> bool {
match self {
Self::Regex(ref s) => s.is_empty(),
Self::Exact(ref v) => v.is_empty(),
}
}
}
impl From<String> for TermsExclude {
fn from(s: String) -> Self {
Self::Regex(s)
}
}
impl From<&str> for TermsExclude {
fn from(s: &str) -> Self {
Self::Regex(s.to_string())
}
}
impl From<Vec<String>> for TermsExclude {
fn from(v: Vec<String>) -> Self {
Self::Exact(v)
}
}
impl From<Vec<&str>> for TermsExclude {
fn from(v: Vec<&str>) -> Self {
Self::Exact(v.iter().map(|s| s.to_string()).collect())
}
}
impl From<&[&str]> for TermsExclude {
fn from(v: &[&str]) -> Self {
Self::Exact(v.iter().map(|s| s.to_string()).collect())
}
}
impl<const N: usize> From<[&str; N]> for TermsExclude {
fn from(value: [&str; N]) -> Self {
Self::Exact(value.iter().map(|s| s.to_string()).collect())
}
}