gitql_ast/types/
range.rs

1use std::any::Any;
2
3use super::base::DataType;
4use super::boolean::BoolType;
5
6#[derive(Clone)]
7pub struct RangeType {
8    pub base: Box<dyn DataType>,
9}
10
11impl RangeType {
12    pub fn new(base: Box<dyn DataType>) -> Self {
13        RangeType { base }
14    }
15}
16
17impl DataType for RangeType {
18    fn literal(&self) -> String {
19        format!("Range({})", self.base.literal())
20    }
21
22    fn equals(&self, other: &Box<dyn DataType>) -> bool {
23        let range_type: Box<dyn DataType> = Box::new(self.clone());
24        if other.is_any() || other.is_variant_contains(&range_type) {
25            return true;
26        }
27
28        if let Some(other_range) = other.as_any().downcast_ref::<RangeType>() {
29            return self.base.equals(&other_range.base);
30        }
31        false
32    }
33
34    fn as_any(&self) -> &dyn Any {
35        self
36    }
37
38    fn can_perform_contains_op_with(&self) -> Vec<Box<dyn DataType>> {
39        vec![Box::new(self.clone()), self.base.clone()]
40    }
41
42    fn can_perform_logical_or_op_with(&self) -> Vec<Box<dyn DataType>> {
43        vec![Box::new(self.clone())]
44    }
45
46    fn logical_or_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
47        Box::new(BoolType)
48    }
49}