FromVariable

Trait FromVariable 

Source
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 to
  • RefOutput<'a> - The borrowed type to convert to
  • MutOutput<'a> - The mutable borrowed type to convert to

§Required Methods

  • from_var - Convert an owned Variable to the target type
  • from_var_ref - Convert a borrowed Variable to the target type
  • from_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§

Source

type Output

The owned output type

Source

type RefOutput<'a> where Self: 'a

The borrowed output type

Source

type MutOutput<'a> where Self: 'a

The mutable borrowed output type

Required Methods§

Source

fn from_var(var: Variable) -> Result<Self::Output, ParseVariableError>

Convert an owned Variable to the target type.

§Parameters
  • var - The Variable to convert
§Returns

Returns Result<Self::Output, ParseVariableError> containing the converted value or an error if the conversion fails.

Source

fn from_var_ref( var: &Variable, ) -> Result<Self::RefOutput<'_>, ParseVariableError>

Convert a borrowed Variable to the target type.

§Parameters
  • var - The Variable to convert
§Returns

Returns Result<Self::RefOutput<'_>, ParseVariableError> containing the converted value or an error if the conversion fails.

Source

fn from_var_mut( var: &mut Variable, ) -> Result<Self::MutOutput<'_>, ParseVariableError>

Convert a mutable borrowed Variable to the target type.

§Parameters
  • var - The Variable to convert
§Returns

Returns Result<Self::MutOutput<'_>, ParseVariableError> containing the converted value or an error if the conversion fails.

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.

Implementations on Foreign Types§

Source§

impl FromVariable for bool

Source§

impl FromVariable for char

Source§

impl FromVariable for f32

Source§

impl FromVariable for f64

Source§

impl FromVariable for i8

Source§

impl FromVariable for i16

Source§

impl FromVariable for i32

Source§

impl FromVariable for i64

Source§

impl FromVariable for u8

Source§

impl FromVariable for u16

Source§

impl FromVariable for u32

Source§

impl FromVariable for u64

Source§

impl FromVariable for String

Source§

impl FromVariable for Vec<Variable>

Source§

impl<T> FromVariable for Vec<T>
where T: FromVariable,

Implementors§