pub struct PluginConfigBuilder { /* private fields */ }Expand description
Builder for creating plugin configurations
The PluginConfigBuilder provides a fluent interface for constructing plugin configurations with various parameters and runtime settings. It ensures type safety and provides convenient methods for common configuration patterns.
§Examples
use sklears_core::plugin::{PluginConfigBuilder, PluginParameter, LogLevel};
let config = PluginConfigBuilder::new()
.with_parameter("learning_rate", PluginParameter::Float(0.01))
.with_parameter("max_iterations", PluginParameter::Int(1000))
.with_parameter("use_bias", PluginParameter::Bool(true))
.with_threads(4)
.with_memory_limit(1024 * 1024 * 1024) // 1GB
.with_timeout(30000) // 30 seconds
.with_gpu(true)
.with_log_level(LogLevel::Info)
.with_setting("backend", "cuda")
.build();Implementations§
Source§impl PluginConfigBuilder
impl PluginConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new config builder
Initializes a new builder with default configuration values.
§Examples
use sklears_core::plugin::PluginConfigBuilder;
let builder = PluginConfigBuilder::new();
let config = builder.build();Sourcepub fn with_parameter(self, key: &str, value: PluginParameter) -> Self
pub fn with_parameter(self, key: &str, value: PluginParameter) -> Self
Add a parameter to the configuration
Adds a named parameter with the specified value to the configuration. This method can be chained to add multiple parameters.
§Arguments
key- The parameter namevalue- The parameter value
§Examples
use sklears_core::plugin::{PluginConfigBuilder, PluginParameter};
let config = PluginConfigBuilder::new()
.with_parameter("learning_rate", PluginParameter::Float(0.01))
.with_parameter("regularization", PluginParameter::Float(0.001))
.build();Sourcepub fn with_parameters(self, params: HashMap<String, PluginParameter>) -> Self
pub fn with_parameters(self, params: HashMap<String, PluginParameter>) -> Self
Add multiple parameters at once
Convenience method for adding multiple parameters from a map.
§Arguments
params- Map of parameter names to values
Sourcepub fn with_threads(self, threads: usize) -> Self
pub fn with_threads(self, threads: usize) -> Self
Set the number of threads to use
Configures the number of threads that the plugin should use for parallel processing. If not set, the plugin will use its default threading behavior.
§Arguments
threads- Number of threads to use
§Examples
use sklears_core::plugin::PluginConfigBuilder;
let config = PluginConfigBuilder::new()
.with_threads(8)
.build();Sourcepub fn with_memory_limit(self, limit: usize) -> Self
pub fn with_memory_limit(self, limit: usize) -> Self
Set memory limit in bytes
Configures the maximum amount of memory that the plugin should use. This can help prevent out-of-memory errors in resource-constrained environments.
§Arguments
limit- Memory limit in bytes
§Examples
use sklears_core::plugin::PluginConfigBuilder;
let config = PluginConfigBuilder::new()
.with_memory_limit(2 * 1024 * 1024 * 1024) // 2GB
.build();Sourcepub fn with_timeout(self, timeout_ms: u64) -> Self
pub fn with_timeout(self, timeout_ms: u64) -> Self
Set timeout in milliseconds
Configures the maximum time that plugin operations should take before timing out. This can help prevent hanging operations.
§Arguments
timeout_ms- Timeout in milliseconds
§Examples
use sklears_core::plugin::PluginConfigBuilder;
let config = PluginConfigBuilder::new()
.with_timeout(60000) // 1 minute
.build();Sourcepub fn with_log_level(self, level: LogLevel) -> Self
pub fn with_log_level(self, level: LogLevel) -> Self
Sourcepub fn with_setting(self, key: &str, value: &str) -> Self
pub fn with_setting(self, key: &str, value: &str) -> Self
Add a plugin-specific setting
Adds a custom setting that is specific to the plugin being configured. These settings are typically used for plugin-specific configuration that doesn’t fit into the standard parameter system.
§Arguments
key- The setting namevalue- The setting value
§Examples
use sklears_core::plugin::PluginConfigBuilder;
let config = PluginConfigBuilder::new()
.with_setting("backend", "tensorflow")
.with_setting("device", "/gpu:0")
.build();Sourcepub fn with_settings(self, settings: HashMap<String, String>) -> Self
pub fn with_settings(self, settings: HashMap<String, String>) -> Self
Add multiple settings at once
Convenience method for adding multiple plugin-specific settings.
§Arguments
settings- Map of setting names to values
Sourcepub fn build(self) -> PluginConfig
pub fn build(self) -> PluginConfig
Build the final configuration
Consumes the builder and returns the constructed configuration.
§Returns
The configured PluginConfig instance.
§Examples
use sklears_core::plugin::{PluginConfigBuilder, PluginParameter};
let config = PluginConfigBuilder::new()
.with_parameter("learning_rate", PluginParameter::Float(0.01))
.with_threads(4)
.build();Sourcepub fn config(&self) -> &PluginConfig
pub fn config(&self) -> &PluginConfig
Get a reference to the current configuration
Returns a reference to the configuration being built without consuming the builder. This can be useful for inspecting the current state during construction.
§Returns
A reference to the current configuration.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate the current configuration
Validates the current configuration state without building it. This can be useful for checking configuration validity during the building process.
§Returns
Ok(()) if the configuration is valid, or an error describing what is invalid.
Sourcepub fn clone_builder(&self) -> Self
pub fn clone_builder(&self) -> Self
Clone the builder
Creates a copy of the current builder state, allowing for branching configuration construction.
§Returns
A cloned builder with the same configuration state.
Source§impl PluginConfigBuilder
Convenience functions for common plugin configurations
impl PluginConfigBuilder
Convenience functions for common plugin configurations
Sourcepub fn cpu_optimized() -> Self
pub fn cpu_optimized() -> Self
Create a configuration optimized for CPU-intensive tasks
Sets up a configuration with appropriate threading and resource settings for CPU-bound algorithms.
Sourcepub fn gpu_optimized() -> Self
pub fn gpu_optimized() -> Self
Create a configuration optimized for GPU acceleration
Sets up a configuration with GPU acceleration enabled and appropriate resource settings.
Sourcepub fn development() -> Self
pub fn development() -> Self
Create a configuration for development/debugging
Sets up a configuration with verbose logging and longer timeouts suitable for development environments.
Sourcepub fn production() -> Self
pub fn production() -> Self
Create a configuration for production environments
Sets up a configuration with optimized settings for production use, including appropriate resource limits and logging levels.
Trait Implementations§
Source§impl Clone for PluginConfigBuilder
impl Clone for PluginConfigBuilder
Source§fn clone(&self) -> PluginConfigBuilder
fn clone(&self) -> PluginConfigBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PluginConfigBuilder
impl Debug for PluginConfigBuilder
Auto Trait Implementations§
impl Freeze for PluginConfigBuilder
impl RefUnwindSafe for PluginConfigBuilder
impl Send for PluginConfigBuilder
impl Sync for PluginConfigBuilder
impl Unpin for PluginConfigBuilder
impl UnwindSafe for PluginConfigBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more