Skip to main content

GeneratorPlugin

Trait GeneratorPlugin 

Source
pub trait GeneratorPlugin: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn description(&self) -> &str;
    fn config_schema(&self) -> Option<Value>;
    fn generate(
        &self,
        config: &Value,
        context: &GenerationContext,
    ) -> Result<Vec<GeneratedRecord>, SynthError>;
}
Expand description

Trait for custom data generator plugins.

Generator plugins produce records based on configuration and context.

§Example

use datasynth_core::traits::plugin::*;
use datasynth_core::error::SynthError;

struct MyGenerator;

impl GeneratorPlugin for MyGenerator {
    fn name(&self) -> &str { "my_generator" }
    fn version(&self) -> &str { "1.0.0" }
    fn description(&self) -> &str { "Generates custom records" }
    fn config_schema(&self) -> Option<serde_json::Value> { None }
    fn generate(
        &self,
        _config: &serde_json::Value,
        _context: &GenerationContext,
    ) -> Result<Vec<GeneratedRecord>, SynthError> {
        Ok(vec![GeneratedRecord::new("custom").with_field("key", "value")])
    }
}

Required Methods§

Source

fn name(&self) -> &str

Unique name identifying this generator.

Source

fn version(&self) -> &str

Semantic version of this plugin.

Source

fn description(&self) -> &str

Human-readable description.

Source

fn config_schema(&self) -> Option<Value>

Optional JSON Schema for plugin configuration.

Source

fn generate( &self, config: &Value, context: &GenerationContext, ) -> Result<Vec<GeneratedRecord>, SynthError>

Generate records given configuration and context.

Implementors§