gitql_ast/types/
optional.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::any::Any;

use super::base::DataType;

#[derive(Clone)]
pub struct OptionType {
    pub base: Option<Box<dyn DataType>>,
}

impl DataType for OptionType {
    fn literal(&self) -> String {
        if let Some(base) = &self.base {
            return format!("{}?", base.literal());
        }
        "None".to_string()
    }

    fn equals(&self, other: &Box<dyn DataType>) -> bool {
        if other.is_any() {
            return true;
        }
        if let Some(base) = &self.base {
            return base.equals(other);
        }
        true
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}