gitql_ast/types/
optional.rs1use std::any::Any;
2
3use super::base::DataType;
4
5#[derive(Clone)]
6pub struct OptionType {
7 pub base: Option<Box<dyn DataType>>,
8}
9
10impl OptionType {
11 pub fn new(base: Option<Box<dyn DataType>>) -> Self {
12 OptionType { base }
13 }
14}
15
16impl DataType for OptionType {
17 fn literal(&self) -> String {
18 if let Some(base) = &self.base {
19 return format!("{}?", base.literal());
20 }
21 "None".to_string()
22 }
23
24 fn equals(&self, other: &Box<dyn DataType>) -> bool {
25 if other.is_any() {
26 return true;
27 }
28 if let Some(base) = &self.base {
29 return base.equals(other);
30 }
31 true
32 }
33
34 fn as_any(&self) -> &dyn Any {
35 self
36 }
37}