Skip to main content

PluginParameter

Enum PluginParameter 

Source
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

Source

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());
Source

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());
Source

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());
Source

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());
Source

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.

Source

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.

Source

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.

Source

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.

Source

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());
Source

pub fn is_float(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_int_array(&self) -> bool

Source

pub fn is_float_array(&self) -> bool

Source

pub fn is_string_array(&self) -> bool

Source

pub fn is_object(&self) -> bool

Source

pub fn type_name(&self) -> &'static str

Get the type name of the parameter

§Returns

A string describing the type of the parameter.

Source§

impl PluginParameter

Convenience functions for creating plugin parameters

Source

pub fn int(value: i64) -> PluginParameter

Create an integer parameter

Source

pub fn float(value: f64) -> PluginParameter

Create a float parameter

Source

pub fn string(value: impl Into<String>) -> PluginParameter

Create a string parameter

Source

pub fn bool(value: bool) -> PluginParameter

Create a boolean parameter

Source

pub fn int_array(value: Vec<i64>) -> PluginParameter

Create an integer array parameter

Source

pub fn float_array(value: Vec<f64>) -> PluginParameter

Create a float array parameter

Source

pub fn string_array(value: Vec<String>) -> PluginParameter

Create a string array parameter

Source

pub fn object(value: HashMap<String, PluginParameter>) -> PluginParameter

Create an object parameter

Trait Implementations§

Source§

impl Clone for PluginParameter

Source§

fn clone(&self) -> PluginParameter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PluginParameter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V