rune

Function from_value

Source
pub fn from_value<T>(value: impl IntoValue) -> Result<T, RuntimeError>
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);