Skip to main content

qcraft_core/ast/
custom.rs

1use std::any::Any;
2use std::fmt::Debug;
3
4// ---------------------------------------------------------------------------
5// Macro to define Custom* traits with common boilerplate
6// ---------------------------------------------------------------------------
7
8macro_rules! define_custom_trait {
9    ($trait_name:ident) => {
10        pub trait $trait_name: Debug + Send + Sync {
11            fn as_any(&self) -> &dyn Any;
12            fn clone_box(&self) -> Box<dyn $trait_name>;
13        }
14
15        impl Clone for Box<dyn $trait_name> {
16            fn clone(&self) -> Self {
17                self.clone_box()
18            }
19        }
20    };
21}
22
23define_custom_trait!(CustomExpr);
24define_custom_trait!(CustomCondition);
25define_custom_trait!(CustomCompareOp);
26define_custom_trait!(CustomTableSource);
27define_custom_trait!(CustomMutation);
28define_custom_trait!(CustomSchemaMutation);
29define_custom_trait!(CustomFieldType);
30define_custom_trait!(CustomBinaryOp);
31define_custom_trait!(CustomConstraint);
32define_custom_trait!(CustomTransaction);