rust_ml/builders/
builder.rs

1/// Builder pattern trait for machine learning models.
2///
3/// This module implements the Builder design pattern for creating machine learning models
4/// with customizable configurations. The Builder pattern separates the construction of complex
5/// objects from their representation, allowing the same construction process to create
6/// different representations.
7///
8/// # Type Parameters
9///
10/// * `M` - The machine learning model type that implements BaseModel
11/// * `Input` - The input data type for the model (typically Matrix)
12/// * `Output` - The output data type for the model (typically Vector)
13use crate::core::error::ModelError;
14use crate::model::core::base::BaseModel;
15
16/// A trait for implementing the Builder pattern for machine learning models.
17///
18/// This trait ensures that any builder can construct a specific model type
19/// through a consistent interface. Builders allow for flexible configuration
20/// of model parameters before instantiation.
21pub trait Builder<M, Input, Output>
22where
23    M: BaseModel<Input, Output>,
24{
25    /// Builds and returns a new model instance with the configured parameters.
26    ///
27    /// # Returns
28    ///
29    /// * `Result<M, ModelError>` - The constructed model if successful, or an error if the
30    ///   construction fails (e.g., due to invalid configuration parameters)
31    fn build(&self) -> Result<M, ModelError>;
32}