1use std::any::Any;
2
3use super::base::DataType;
4
5#[derive(Clone)]
6pub struct RowType {
7 pub tuple: Vec<Box<dyn DataType>>,
8}
9
10impl RowType {
11 pub fn new(tuple: Vec<Box<dyn DataType>>) -> Self {
12 RowType { tuple }
13 }
14}
15
16impl DataType for RowType {
17 fn literal(&self) -> String {
18 let mut str = String::new();
19 let last_position = self.tuple.len() - 1;
20 str += "Row(";
21 for (pos, data_type) in self.tuple.iter().enumerate() {
22 str += &data_type.literal();
23 if pos != last_position {
24 str += ", ";
25 }
26 }
27 str += ")";
28 str
29 }
30
31 fn equals(&self, other: &Box<dyn DataType>) -> bool {
32 let row_type: Box<dyn DataType> = Box::new(self.clone());
33 if other.is_any() || other.is_variant_contains(&row_type) {
34 return true;
35 }
36
37 if let Some(other_row) = other.as_any().downcast_ref::<RowType>() {
38 if self.tuple.len() != other_row.tuple.len() {
39 return false;
40 }
41
42 let len = self.tuple.len();
43 for i in 0..len {
44 if !self.tuple[i].eq(&other_row.tuple[i]) {
45 return false;
46 }
47 }
48
49 return true;
50 }
51
52 false
53 }
54
55 fn as_any(&self) -> &dyn Any {
56 self
57 }
58}