gitql_ast/types/
dynamic.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
32
33
use std::any::Any;

use super::base::DataType;

/// A function that resolve a dynamic type depending on a list of already resolved types
pub type ResolveFunction = fn(&[Box<dyn DataType>]) -> Box<dyn DataType>;

#[derive(Clone)]
#[allow(clippy::borrowed_box)]
pub struct DynamicType {
    pub function: ResolveFunction,
}

impl DynamicType {
    #[allow(clippy::type_complexity)]
    pub fn new(function: ResolveFunction) -> Self {
        DynamicType { function }
    }
}

impl DataType for DynamicType {
    fn literal(&self) -> String {
        "Dynamic".to_string()
    }

    fn equals(&self, _other: &Box<dyn DataType>) -> bool {
        false
    }

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