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