use crate::Result;
use crate::field_generators::GenerationContext;
pub trait FieldGenerator: Send + Sync {
fn generate(&self, context: &GenerationContext) -> Result<String>;
fn name(&self) -> &str;
fn supported_datatypes(&self) -> Vec<String>;
fn can_handle(&self, context: &GenerationContext) -> bool {
self.supported_datatypes().contains(&context.datatype)
}
}
pub trait FieldGeneratorFactory: Send + Sync {
fn create(&self) -> Result<Box<dyn FieldGenerator>>;
fn generator_name(&self) -> &str;
}
#[macro_export]
macro_rules! impl_field_generator {
($struct_name:ident, $name:expr, $datatypes:expr) => {
impl FieldGenerator for $struct_name {
fn name(&self) -> &str {
$name
}
fn supported_datatypes(&self) -> Vec<String> {
$datatypes.iter().map(|s| s.to_string()).collect()
}
}
};
}