pub enum PluginParameter {
Int(i64),
Float(f64),
String(String),
Bool(bool),
IntArray(Vec<i64>),
FloatArray(Vec<f64>),
StringArray(Vec<String>),
Object(HashMap<String, PluginParameter>),
}Expand description
Plugin parameter types
This enum provides type-safe parameter handling for plugin configuration. It supports common parameter types and nested structures for complex configurations.
§Examples
use sklears_core::plugin::PluginParameter;
use std::collections::HashMap;
// Simple parameters
let learning_rate = PluginParameter::Float(0.01);
let max_iterations = PluginParameter::Int(1000);
let use_bias = PluginParameter::Bool(true);
let algorithm_name = PluginParameter::String("adam".to_string());
// Array parameters
let layer_sizes = PluginParameter::IntArray(vec![100, 50, 10]);
let dropout_rates = PluginParameter::FloatArray(vec![0.2, 0.3, 0.5]);
// Nested parameters
let mut optimizer_config = HashMap::new();
optimizer_config.insert("type".to_string(), PluginParameter::String("adam".to_string()));
optimizer_config.insert("beta1".to_string(), PluginParameter::Float(0.9));
optimizer_config.insert("beta2".to_string(), PluginParameter::Float(0.999));
let optimizer = PluginParameter::Object(optimizer_config);Variants§
Int(i64)
Integer parameter
Float(f64)
Floating-point parameter
String(String)
String parameter
Bool(bool)
Boolean parameter
IntArray(Vec<i64>)
Array of integers
FloatArray(Vec<f64>)
Array of floats
StringArray(Vec<String>)
Array of strings
Object(HashMap<String, PluginParameter>)
Nested parameters for complex configurations
Implementations§
Source§impl PluginParameter
impl PluginParameter
Sourcepub fn as_int(&self) -> Result<i64, SklearsError>
pub fn as_int(&self) -> Result<i64, SklearsError>
Try to extract an integer value
§Returns
The integer value if the parameter is an Int, otherwise an error.
§Examples
use sklears_core::plugin::PluginParameter;
let param = PluginParameter::Int(42);
assert_eq!(param.as_int().expect("Int parameter must return value"), 42);
let param = PluginParameter::String("not a number".to_string());
assert!(param.as_int().is_err());Sourcepub fn as_float(&self) -> Result<f64, SklearsError>
pub fn as_float(&self) -> Result<f64, SklearsError>
Try to extract a float value
This method also supports converting integers to floats.
§Returns
The float value if the parameter is numeric, otherwise an error.
§Examples
use sklears_core::plugin::PluginParameter;
let param = PluginParameter::Float(3.14);
assert_eq!(param.as_float().expect("Float parameter must return value"), 3.14);
let param = PluginParameter::Int(42);
assert_eq!(param.as_float().expect("Int parameter must convert to float"), 42.0);
let param = PluginParameter::Bool(true);
assert!(param.as_float().is_err());Sourcepub fn as_string(&self) -> Result<&str, SklearsError>
pub fn as_string(&self) -> Result<&str, SklearsError>
Try to extract a string value
§Returns
A reference to the string value if the parameter is a String, otherwise an error.
§Examples
use sklears_core::plugin::PluginParameter;
let param = PluginParameter::String("hello".to_string());
assert_eq!(param.as_string().expect("String parameter must return value"), "hello");
let param = PluginParameter::Int(42);
assert!(param.as_string().is_err());Sourcepub fn as_bool(&self) -> Result<bool, SklearsError>
pub fn as_bool(&self) -> Result<bool, SklearsError>
Try to extract a boolean value
§Returns
The boolean value if the parameter is a Bool, otherwise an error.
§Examples
use sklears_core::plugin::PluginParameter;
let param = PluginParameter::Bool(true);
assert_eq!(param.as_bool().expect("Bool parameter must return value"), true);
let param = PluginParameter::String("true".to_string());
assert!(param.as_bool().is_err());Sourcepub fn as_int_array(&self) -> Result<&Vec<i64>, SklearsError>
pub fn as_int_array(&self) -> Result<&Vec<i64>, SklearsError>
Try to extract an integer array
§Returns
A reference to the integer array if the parameter is an IntArray, otherwise an error.
Sourcepub fn as_float_array(&self) -> Result<&Vec<f64>, SklearsError>
pub fn as_float_array(&self) -> Result<&Vec<f64>, SklearsError>
Try to extract a float array
§Returns
A reference to the float array if the parameter is a FloatArray, otherwise an error.
Sourcepub fn as_string_array(&self) -> Result<&Vec<String>, SklearsError>
pub fn as_string_array(&self) -> Result<&Vec<String>, SklearsError>
Try to extract a string array
§Returns
A reference to the string array if the parameter is a StringArray, otherwise an error.
Sourcepub fn as_object(
&self,
) -> Result<&HashMap<String, PluginParameter>, SklearsError>
pub fn as_object( &self, ) -> Result<&HashMap<String, PluginParameter>, SklearsError>
Try to extract a nested object
§Returns
A reference to the nested parameter map if the parameter is an Object, otherwise an error.
Sourcepub fn is_int(&self) -> bool
pub fn is_int(&self) -> bool
Check if the parameter is of a specific type
§Examples
use sklears_core::plugin::PluginParameter;
let param = PluginParameter::Float(3.14);
assert!(param.is_float());
assert!(!param.is_int());pub fn is_float(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_int_array(&self) -> bool
pub fn is_float_array(&self) -> bool
pub fn is_string_array(&self) -> bool
pub fn is_object(&self) -> bool
Source§impl PluginParameter
Convenience functions for creating plugin parameters
impl PluginParameter
Convenience functions for creating plugin parameters
Sourcepub fn int(value: i64) -> PluginParameter
pub fn int(value: i64) -> PluginParameter
Create an integer parameter
Sourcepub fn float(value: f64) -> PluginParameter
pub fn float(value: f64) -> PluginParameter
Create a float parameter
Sourcepub fn string(value: impl Into<String>) -> PluginParameter
pub fn string(value: impl Into<String>) -> PluginParameter
Create a string parameter
Sourcepub fn bool(value: bool) -> PluginParameter
pub fn bool(value: bool) -> PluginParameter
Create a boolean parameter
Sourcepub fn int_array(value: Vec<i64>) -> PluginParameter
pub fn int_array(value: Vec<i64>) -> PluginParameter
Create an integer array parameter
Sourcepub fn float_array(value: Vec<f64>) -> PluginParameter
pub fn float_array(value: Vec<f64>) -> PluginParameter
Create a float array parameter
Sourcepub fn string_array(value: Vec<String>) -> PluginParameter
pub fn string_array(value: Vec<String>) -> PluginParameter
Create a string array parameter
Sourcepub fn object(value: HashMap<String, PluginParameter>) -> PluginParameter
pub fn object(value: HashMap<String, PluginParameter>) -> PluginParameter
Create an object parameter
Trait Implementations§
Source§impl Clone for PluginParameter
impl Clone for PluginParameter
Source§fn clone(&self) -> PluginParameter
fn clone(&self) -> PluginParameter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PluginParameter
impl RefUnwindSafe for PluginParameter
impl Send for PluginParameter
impl Sync for PluginParameter
impl Unpin for PluginParameter
impl UnsafeUnpin for PluginParameter
impl UnwindSafe for PluginParameter
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.