Skip to main content

ModelLoad

Trait ModelLoad 

Source
pub trait ModelLoad: Sized {
    // Required methods
    fn load(path: &str) -> Result<Self, Error>;
    fn from_serialized(model: SerializedModel) -> Result<Self, Error>;
    fn model_type() -> ModelType;
}
Expand description

Trait for loading models from disk.

This trait is implemented by all regression result types that support deserialization. Loading validates the format version and model type.

§Example

let model: RegressionOutput = RegressionOutput::load("my_model.json").unwrap();
println!("R²: {}", model.r_squared);

Required Methods§

Source

fn load(path: &str) -> Result<Self, Error>

Load a model from a file.

This validates that:

  • The file exists and contains valid JSON
  • The format version is compatible
  • The model type matches the expected type
§Arguments
  • path - File path to load from
§Returns

Returns the deserialized model on success, or an Error if loading fails.

Source

fn from_serialized(model: SerializedModel) -> Result<Self, Error>

Load a model from an already-deserialized wrapper.

This is useful when you have a SerializedModel and want to convert it to a specific model type.

§Arguments
  • model - The serialized model wrapper
§Returns

Returns the deserialized model on success, or an Error if conversion fails.

Source

fn model_type() -> ModelType

Get the model type identifier.

This is used to validate that the loaded file contains the correct model type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§