1use std::any::Any;
2
3use super::base::DataType;
4use super::boolean::BoolType;
5use super::integer::IntType;
6
7#[derive(Clone)]
8pub struct ArrayType {
9 pub base: Box<dyn DataType>,
10}
11
12impl ArrayType {
13 pub fn new(base: Box<dyn DataType>) -> Self {
14 ArrayType { base }
15 }
16}
17
18impl DataType for ArrayType {
19 fn literal(&self) -> String {
20 format!("Array({})", self.base.literal())
21 }
22
23 fn equals(&self, other: &Box<dyn DataType>) -> bool {
24 let array_type: Box<dyn DataType> = Box::new(self.clone());
25 if other.is_any() || other.is_variant_contains(&array_type) {
26 return true;
27 }
28
29 if let Some(other_array) = other.as_any().downcast_ref::<ArrayType>() {
30 return self.base.equals(&other_array.base);
31 }
32 false
33 }
34
35 fn as_any(&self) -> &dyn Any {
36 self
37 }
38
39 fn can_perform_index_op_with(&self) -> Vec<Box<dyn DataType>> {
40 vec![Box::new(IntType)]
41 }
42
43 fn index_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
44 self.base.clone()
45 }
46
47 fn can_perform_slice_op(&self) -> bool {
48 true
49 }
50
51 fn can_perform_slice_op_with(&self) -> Vec<Box<dyn DataType>> {
52 vec![Box::new(IntType)]
53 }
54
55 fn can_perform_contains_op_with(&self) -> Vec<Box<dyn DataType>> {
56 vec![Box::new(self.clone()), self.base.clone()]
57 }
58
59 fn can_perform_logical_or_op_with(&self) -> Vec<Box<dyn DataType>> {
60 vec![Box::new(self.clone())]
61 }
62
63 fn logical_or_op_result_type(&self, _other: &Box<dyn DataType>) -> Box<dyn DataType> {
64 Box::new(BoolType)
65 }
66}