pub enum Variable {
}
Expand description
Represents a dynamically typed value that can be passed between plugins.
Variable is the core data type used for communication between plugins and the host. It supports all common data types and provides type-safe conversion methods.
§Variants
Null
- Represents a null/empty value (default)I8
,I16
,I32
,I64
- Signed integer typesU8
,U16
,U32
,U64
- Unsigned integer typesF32
,F64
- Floating point typesBool
- Boolean valuesChar
- Unicode charactersString
- UTF-8 stringsList
- Lists/arrays of variables
§Examples
use plux_rs::variable::Variable;
// Create variables of different types
let num = Variable::I32(42);
let text = Variable::String("Hello".to_string());
let flag = Variable::Bool(true);
let list = Variable::List(vec![num, text, flag]);
// Convert from Rust types
let var1: Variable = 42_i32.into();
let var2: Variable = "hello".into();
let var3: Variable = vec![1, 2, 3].into();
Variants§
Null
Null/empty value
I8(i8)
8-bit signed integer
I16(i16)
16-bit signed integer
I32(i32)
32-bit signed integer
I64(i64)
64-bit signed integer
U8(u8)
8-bit unsigned integer
U16(u16)
16-bit unsigned integer
U32(u32)
32-bit unsigned integer
U64(u64)
64-bit unsigned integer
F32(f32)
32-bit floating point
F64(f64)
64-bit floating point
Bool(bool)
Boolean value
Char(char)
Unicode character
String(String)
UTF-8 string
List(Vec<Variable>)
List of variables
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn parse<F>(self) -> F::Outputwhere
F: FromVariable,
pub fn parse<F>(self) -> F::Outputwhere
F: FromVariable,
Parse the Variable into a specific type (panics on error).
This method converts the Variable to the specified type, panicking if the conversion fails. Use this when you’re certain about the type.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns the converted value of type F::Output
.
§Panics
Panics if the Variable cannot be converted to the target type.
§Example
use plux_rs::variable::Variable;
let var = Variable::I32(42);
let num: i32 = var.parse::<i32>();
assert_eq!(num, 42);
Sourcepub fn parse_ref<F>(&self) -> F::RefOutput<'_>where
F: FromVariable,
pub fn parse_ref<F>(&self) -> F::RefOutput<'_>where
F: FromVariable,
Parse the Variable into a specific type by reference (panics on error).
This method converts the Variable to the specified type without consuming it, panicking if the conversion fails.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns a reference to the converted value of type F::RefOutput<'_>
.
§Panics
Panics if the Variable cannot be converted to the target type.
Sourcepub fn parse_mut<F>(&mut self) -> F::MutOutput<'_>where
F: FromVariable,
pub fn parse_mut<F>(&mut self) -> F::MutOutput<'_>where
F: FromVariable,
Parse the Variable into a specific type by mutable reference (panics on error).
This method converts the Variable to the specified type without consuming it, panicking if the conversion fails.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns a mutable reference to the converted value of type F::MutOutput<'_>
.
§Panics
Panics if the Variable cannot be converted to the target type.
Sourcepub fn try_parse<F>(self) -> Result<F::Output, ParseVariableError>where
F: FromVariable,
pub fn try_parse<F>(self) -> Result<F::Output, ParseVariableError>where
F: FromVariable,
Try to parse the Variable into a specific type.
This method attempts to convert the Variable to the specified type, returning an error if the conversion fails.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns Result<F::Output, ParseVariableError>
containing the converted value
or an error if the conversion fails.
§Example
use plux_rs::variable::Variable;
let var = Variable::I32(42);
match var.try_parse::<i32>() {
Ok(num) => println!("Parsed: {}", num),
Err(e) => println!("Parse error: {}", e),
}
Sourcepub fn try_parse_ref<F>(&self) -> Result<F::RefOutput<'_>, ParseVariableError>where
F: FromVariable,
pub fn try_parse_ref<F>(&self) -> Result<F::RefOutput<'_>, ParseVariableError>where
F: FromVariable,
Try to parse the Variable into a specific type by reference.
This method attempts to convert the Variable to the specified type without consuming it, returning an error if the conversion fails.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns Result<F::RefOutput<'_>, ParseVariableError>
containing a reference to the
converted value or an error if the conversion fails.
Sourcepub fn try_parse_mut<F>(
&mut self,
) -> Result<F::MutOutput<'_>, ParseVariableError>where
F: FromVariable,
pub fn try_parse_mut<F>(
&mut self,
) -> Result<F::MutOutput<'_>, ParseVariableError>where
F: FromVariable,
Try to parse the Variable into a specific type by mutable reference.
This method attempts to convert the Variable to the specified type without consuming it, returning an error if the conversion fails.
§Type Parameters
F
- The target type that implements FromVariable
§Returns
Returns Result<F::MutOutput<'_>, ParseVariableError>
containing a mutable reference to the
converted value or an error if the conversion fails.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Variable
impl<'de> Deserialize<'de> for Variable
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialOrd for Variable
impl PartialOrd for Variable
impl StructuralPartialEq for Variable
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnwindSafe for Variable
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