Skip to main content

sklears_compose/plugin_architecture/
exampletransformerfactory_traits.rs

1//! # ExampleTransformerFactory - Trait Implementations
2//!
3//! This module contains trait implementations for `ExampleTransformerFactory`.
4//!
5//! ## Implemented Traits
6//!
7//! - `ComponentFactory`
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::{ComponentFactory, PluginComponent};
18use super::types::{
19    ComponentConfig, ComponentSchema, ConfigValue, ExampleScaler, ExampleTransformerFactory,
20    ParameterSchema, ParameterType,
21};
22
23impl ComponentFactory for ExampleTransformerFactory {
24    fn create(
25        &self,
26        component_type: &str,
27        config: &ComponentConfig,
28    ) -> SklResult<Box<dyn PluginComponent>> {
29        match component_type {
30            "example_scaler" => Ok(Box::new(ExampleScaler::new(config.clone()))),
31            _ => Err(SklearsError::InvalidInput(format!(
32                "Unknown component type: {component_type}"
33            ))),
34        }
35    }
36    fn available_types(&self) -> Vec<String> {
37        vec!["example_scaler".to_string()]
38    }
39    fn get_schema(&self, component_type: &str) -> Option<ComponentSchema> {
40        match component_type {
41            "example_scaler" => Some(ComponentSchema {
42                name: "ExampleScaler".to_string(),
43                required_parameters: vec![],
44                optional_parameters: vec![ParameterSchema {
45                    name: "scale_factor".to_string(),
46                    parameter_type: ParameterType::Float {
47                        min_value: Some(0.0),
48                        max_value: None,
49                    },
50                    description: "Factor to scale features by".to_string(),
51                    default_value: Some(ConfigValue::Float(1.0)),
52                }],
53                constraints: vec![],
54            }),
55            _ => None,
56        }
57    }
58}