gitql_ast/types/
dynamic.rs

1use std::any::Any;
2
3use super::base::DataType;
4
5/// A function that resolve a dynamic type depending on a list of already resolved types
6pub type ResolveFunction = fn(&[Box<dyn DataType>]) -> Box<dyn DataType>;
7
8#[derive(Clone)]
9#[allow(clippy::borrowed_box)]
10pub struct DynamicType {
11    pub function: ResolveFunction,
12}
13
14impl DynamicType {
15    #[allow(clippy::type_complexity)]
16    pub fn new(function: ResolveFunction) -> Self {
17        DynamicType { function }
18    }
19}
20
21impl DataType for DynamicType {
22    fn literal(&self) -> String {
23        "Dynamic".to_string()
24    }
25
26    fn equals(&self, _other: &Box<dyn DataType>) -> bool {
27        false
28    }
29
30    fn as_any(&self) -> &dyn Any {
31        self
32    }
33}