os_query_builder_rs/full_text/intervals/rules/
all_of.rs1use serde::Serialize;
2use crate::full_text::intervals::{
3 interval_rule::IntervalRule,
4 rules::filter::FilterRule
5};
6
7#[derive(Debug, Default, Clone, Serialize)]
8pub struct AllOfRule {
9 interval: Vec<IntervalRule>,
10 #[serde(skip_serializing_if = "Option::is_none")]
11 filter: Option<Box<FilterRule>>,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 max_gaps: Option<i64>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 ordered: Option<bool>
16}
17
18impl AllOfRule {
19 pub fn new() -> Self {
20 Self::default()
21 }
22
23 pub fn intervals<T,F>(self, intervals: F) -> Self
24 where T: Into<IntervalRule> + Serialize,
25 F: IntoIterator<Item=T>
26 {
27 Self {
28 interval: intervals.into_iter().map(|x| x.into()).collect(),
29 ..self
30 }
31 }
32
33 pub fn filter<T:Into<FilterRule>>(self, filter: T) -> Self {
34 Self {
35 filter: Some(Box::new(filter.into())),
36 ..self
37 }
38 }
39
40 pub fn max_gaps<T: Into<i64> + Serialize>(self, max_gaps: T) -> Self {
41 Self {
42 max_gaps: Some(max_gaps.into()),
43 ..self
44 }
45 }
46
47 pub fn ordered<T: Into<bool> + Serialize>(self, ordered: T) -> Self {
48 Self {
49 ordered: Some(ordered.into()),
50 ..self
51 }
52 }
53}