rune

Derive Macro ToValue

Source
#[derive(ToValue)]
{
    // Attributes available to this derive:
    #[rune]
}
Expand description

Derive macro for the ToValue trait for converting types into the dynamic Value container.

ยง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 value = vm.call(["main"], (Foo { field: 42 },))?;
let value: u64 = rune::from_value(value)?;

assert_eq!(value, 43);