elasticsearch_dsl/search/aggregations/params/
terms_include.rs1use crate::util::ShouldSkip;
2
3#[derive(Debug, Clone, Serialize, PartialEq)]
5#[serde(untagged)]
6pub enum TermsInclude {
7 Regex(String),
11
12 Exact(Vec<String>),
16
17 Partitions {
21 partition: u32,
23 num_partitions: u32,
25 },
26}
27
28impl ShouldSkip for TermsInclude {
29 fn should_skip(&self) -> bool {
30 match self {
31 Self::Regex(ref s) => s.is_empty(),
32 Self::Exact(ref v) => v.is_empty(),
33 Self::Partitions { .. } => false,
34 }
35 }
36}
37
38impl From<String> for TermsInclude {
39 fn from(s: String) -> Self {
40 Self::Regex(s)
41 }
42}
43
44impl From<&str> for TermsInclude {
45 fn from(s: &str) -> Self {
46 Self::Regex(s.to_string())
47 }
48}
49
50impl From<Vec<String>> for TermsInclude {
51 fn from(v: Vec<String>) -> Self {
52 Self::Exact(v)
53 }
54}
55
56impl From<Vec<&str>> for TermsInclude {
57 fn from(v: Vec<&str>) -> Self {
58 Self::Exact(v.iter().map(|s| s.to_string()).collect())
59 }
60}
61
62impl From<&[&str]> for TermsInclude {
63 fn from(v: &[&str]) -> Self {
64 Self::Exact(v.iter().map(|s| s.to_string()).collect())
65 }
66}
67
68impl<const N: usize> From<[&str; N]> for TermsInclude {
69 fn from(value: [&str; N]) -> Self {
70 Self::Exact(value.iter().map(|s| s.to_string()).collect())
71 }
72}
73
74impl From<(u32, u32)> for TermsInclude {
75 fn from(value: (u32, u32)) -> Self {
76 Self::Partitions {
77 partition: value.0,
78 num_partitions: value.1,
79 }
80 }
81}
82
83impl From<[u32; 2]> for TermsInclude {
84 fn from(value: [u32; 2]) -> Self {
85 Self::Partitions {
86 partition: value[0],
87 num_partitions: value[1],
88 }
89 }
90}