Function rune::runtime::from_value

source ·
pub fn from_value<T>(value: Value) -> Result<T, VmError>
where T: FromValue,
Expand description

Convert something into the dynamic Value.

§Examples

use rune::{ToValue, Vm};
use std::sync::Arc;

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

let mut sources = rune::sources! {
    entry => {
        pub fn main(foo) {
            foo.field + 1
        }
    }
};

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

let mut vm = Vm::without_runtime(Arc::new(unit));
let foo = vm.call(["main"], (Foo { field: 42 },))?;
let foo: u64 = rune::from_value(foo)?;

assert_eq!(foo, 43);