core_api_client/models/query_models/
filter_operator.rs1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd, Hash)]
31pub enum FilterOperator<T1, T2>
32where
33 T1: ToString,
34 T2: ToString,
35{
36 Smaller(T1, T2),
37 Bigger(T1, T2),
38 Eq(T1, T2),
39 SmallerEq(T1, T2),
40 BiggerEq(T1, T2),
41 Exists(T1),
42 HasValue(T1, T2),
43}
44
45
46impl<T1, T2> FilterOperator<T1, T2>
47where
48 T1: ToString,
49 T2: ToString,
50{
51 pub(crate) fn parse(self) -> String {
52 match self {
53 FilterOperator::Smaller(key, value) => format!("{}<{}", key.to_string(), value.to_string()),
54 FilterOperator::Bigger(key, value) => format!("{}>{}", key.to_string(), value.to_string()),
55 FilterOperator::Eq(key, value) => format!("{}={}", key.to_string(), value.to_string()),
56 FilterOperator::SmallerEq(key, value) => format!("{}<={}", key.to_string(), value.to_string()),
57 FilterOperator::BiggerEq(key, value) => format!("{}>={}", key.to_string(), value.to_string()),
58 FilterOperator::Exists(key) => format!("_exists_:{}", key.to_string()),
59 FilterOperator::HasValue(key, value) => format!("{}:{}", key.to_string(), value.to_string()),
60 }
61 }
62}
63
64impl<T1, T2> fmt::Display for FilterOperator<T1, T2>
65where
66 T1: ToString,
67 T2: ToString,
68{
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 match self {
71 FilterOperator::Smaller(t1, t2) => write!(f, "Smaller({}, {})", t1.to_string(), t2.to_string()),
72 FilterOperator::Bigger(t1, t2) => write!(f, "Bigger({}, {})", t1.to_string(), t2.to_string()),
73 FilterOperator::Eq(t1, t2) => write!(f, "Eq({}, {})", t1.to_string(), t2.to_string()),
74 FilterOperator::SmallerEq(t1, t2) => write!(f, "SmallerEq({}, {})", t1.to_string(), t2.to_string()),
75 FilterOperator::BiggerEq(t1, t2) => write!(f, "BiggerEq({}, {})", t1.to_string(), t2.to_string()),
76 FilterOperator::Exists(t1) => write!(f, "Exists({})", t1.to_string()),
77 FilterOperator::HasValue(t1, t2) => write!(f, "HasValue({}, {})", t1.to_string(), t2.to_string()),
78 }
79 }
80}