Skip to main content

sklears_compose/plugin_architecture/
exampletransformerplugin_traits.rs

1//! # ExampleTransformerPlugin - Trait Implementations
2//!
3//! This module contains trait implementations for `ExampleTransformerPlugin`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Plugin`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use sklears_core::{
12    error::{Result as SklResult, SklearsError},
13    traits::Estimator,
14    types::Float,
15};
16
17use super::functions::{Plugin, PluginComponent};
18use super::types::{
19    ComponentConfig, ComponentSchema, ConfigValue, ExampleScaler, ExampleTransformerPlugin,
20    ParameterSchema, ParameterType, PluginCapability, PluginContext, PluginMetadata,
21};
22
23impl Plugin for ExampleTransformerPlugin {
24    fn metadata(&self) -> &PluginMetadata {
25        &self.metadata
26    }
27    fn initialize(&mut self, _context: &PluginContext) -> SklResult<()> {
28        Ok(())
29    }
30    fn shutdown(&mut self) -> SklResult<()> {
31        Ok(())
32    }
33    fn capabilities(&self) -> Vec<PluginCapability> {
34        vec![PluginCapability::Transformer]
35    }
36    fn create_component(
37        &self,
38        component_type: &str,
39        config: &ComponentConfig,
40    ) -> SklResult<Box<dyn PluginComponent>> {
41        match component_type {
42            "example_scaler" => Ok(Box::new(ExampleScaler::new(config.clone()))),
43            _ => Err(SklearsError::InvalidInput(format!(
44                "Unknown component type: {component_type}"
45            ))),
46        }
47    }
48    fn validate_config(&self, _config: &ComponentConfig) -> SklResult<()> {
49        Ok(())
50    }
51    fn get_component_schema(&self, component_type: &str) -> Option<ComponentSchema> {
52        match component_type {
53            "example_scaler" => Some(ComponentSchema {
54                name: "ExampleScaler".to_string(),
55                required_parameters: vec![],
56                optional_parameters: vec![ParameterSchema {
57                    name: "scale_factor".to_string(),
58                    parameter_type: ParameterType::Float {
59                        min_value: Some(0.0),
60                        max_value: None,
61                    },
62                    description: "Factor to scale features by".to_string(),
63                    default_value: Some(ConfigValue::Float(1.0)),
64                }],
65                constraints: vec![],
66            }),
67            _ => None,
68        }
69    }
70}