| 67 | } |
| 68 | |
| 69 | fn group_eq_op( |
| 70 | &self, |
| 71 | other: &Box<dyn Value>, |
| 72 | group_op: &GroupComparisonOperator, |
| 73 | ) -> Result<Box<dyn Value>, String> { |
| 74 | if other.is_array_of(|element_type| element_type.is_text()) { |
| 75 | let elements = &other.as_array().unwrap(); |
| 76 | let mut matches_count = 0; |
| 77 | for element in elements.iter() { |
| 78 | if self.value == element.as_text().unwrap() { |
| 79 | matches_count += 1; |
| 80 | if GroupComparisonOperator::Any.eq(group_op) { |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | let result = match group_op { |
| 87 | GroupComparisonOperator::All => matches_count == elements.len(), |
| 88 | GroupComparisonOperator::Any => matches_count > 0, |
| 89 | }; |
| 90 | |
| 91 | return Ok(Box::new(BoolValue::new(result))); |
| 92 | } |
| 93 | Err("Unexpected type to perform `=` with".to_string()) |
| 94 | } |
| 95 | |
| 96 | fn bang_eq_op(&self, other: &Box<dyn Value>) -> Result<Box<dyn Value>, String> { |
| 97 | if let Some(other_text) = other.as_any().downcast_ref::<TextValue>() { |