Trait rune::FromValue[][src]

pub trait FromValue: 'static + Sized {
    fn from_value(value: Value) -> Result<Self, VmError>;
}
Expand description

Trait for converting types from the dynamic Value container.

Examples

use rune::{Context, FromValue, Sources, Source, Vm};
use std::sync::Arc;

#[derive(FromValue)]
struct Foo {
    field: u64,
}

let mut sources = rune::sources!(entry => {
    pub fn main() { #{field: 42} }
});

let unit = rune::prepare(&mut sources).build()?;

let mut vm = Vm::without_runtime(Arc::new(unit));
let foo = vm.call(&["main"], ())?;
let foo = Foo::from_value(foo)?;

assert_eq!(foo.field, 42);

Required methods

Try to convert to the given type, from the given value.

Implementations on Foreign Types

Implementors