pub trait ToValue: Sized {
// Required method
fn to_value(self) -> Result<Value, RuntimeError>;
}
Expand description
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 foo = vm.call(["main"], (Foo { field: 42 },))?;
let foo: u64 = rune::from_value(foo)?;
assert_eq!(foo, 43);
Required Methods§
Sourcefn to_value(self) -> Result<Value, RuntimeError>
fn to_value(self) -> Result<Value, RuntimeError>
Convert into a value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.