kimari/operator/
any.rs

1use crate::context::Context;
2use serde::{Deserialize, Serialize};
3
4use crate::decision::Decision;
5use crate::operator::{Error, Operate};
6use crate::value::Value;
7use crate::Operator;
8
9#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
10pub struct Any {
11    pub operators: Vec<Operator>,
12}
13
14impl Operate for Any {
15    fn operate<C>(&self, context: &C) -> Result<Decision, Error>
16    where
17        C: Context,
18    {
19        Decision::try_from_iter_any(self.operators.iter().map(|o| o.operate(context)))
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use crate::operator;
27
28    #[test]
29    fn deserialize() {
30        // language=yaml
31        let yaml = r#"
32        operators:
33          - type: equals
34            where: foo.bar
35            to: 123
36          - type: notEquals
37            where: foo.bar
38            to: abc
39        "#;
40
41        let operator = serde_yaml::from_str::<Any>(yaml).unwrap();
42
43        assert_eq!(
44            Any {
45                operators: vec![
46                    Operator::Equals(operator::Equals {
47                        r#where: "foo.bar".to_string(),
48                        to: Value::from(123),
49                    }),
50                    Operator::NotEquals(operator::NotEquals {
51                        r#where: "foo.bar".to_string(),
52                        to: Value::from("abc"),
53                    })
54                ]
55            },
56            operator,
57        );
58    }
59}