Derive Macro rune_macros::ToValue[][src]

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

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

Examples

use rune::{FromValue, 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::from_value(foo)?;

assert_eq!(foo, 43);