pub trait FromVariable {
type Output;
type RefOutput<'a>
where Self: 'a;
type MutOutput<'a>
where Self: 'a;
// Required methods
fn from_var(var: Variable) -> Result<Self::Output, ParseVariableError>;
fn from_var_ref(
var: &Variable,
) -> Result<Self::RefOutput<'_>, ParseVariableError>;
fn from_var_mut(
var: &mut Variable,
) -> Result<Self::MutOutput<'_>, ParseVariableError>;
}
Expand description
Trait for converting Variables to specific Rust types.
FromVariable provides methods to safely convert Variables to their corresponding Rust types. It supports owned, borrowed, and mutable borrowed conversions.
§Type Parameters
Output
- The owned type to convert toRefOutput<'a>
- The borrowed type to convert toMutOutput<'a>
- The mutable borrowed type to convert to
§Required Methods
from_var
- Convert an owned Variable to the target typefrom_var_ref
- Convert a borrowed Variable to the target typefrom_var_mut
- Convert a mutable borrowed Variable to the target type
§Example
use plux_rs::variable::{Variable, FromVariable};
let var = Variable::I32(42);
// Convert to owned value
let owned: i32 = i32::from_var(var).unwrap();
// Convert to borrowed value
let var_ref = &Variable::I32(42);
let borrowed: &i32 = i32::from_var_ref(var_ref).unwrap();
Required Associated Types§
Required Methods§
Sourcefn from_var_ref(
var: &Variable,
) -> Result<Self::RefOutput<'_>, ParseVariableError>
fn from_var_ref( var: &Variable, ) -> Result<Self::RefOutput<'_>, ParseVariableError>
Sourcefn from_var_mut(
var: &mut Variable,
) -> Result<Self::MutOutput<'_>, ParseVariableError>
fn from_var_mut( var: &mut Variable, ) -> Result<Self::MutOutput<'_>, ParseVariableError>
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.