pub trait FromValue: 'static + Sized {
// Required method
fn from_value(value: Value) -> VmResult<Self>;
}
Expand description
Trait for converting types from the dynamic Value container.
§Examples
use rune::{FromValue, Vm};
use std::sync::Arc;
#[derive(FromValue)]
struct Foo {
field: u64,
}
let mut sources = rune::sources!(entry => {
pub fn main() { #{field: 42} }
});
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let foo = vm.call(["main"], ())?;
let foo: Foo = rune::from_value(foo)?;
assert_eq!(foo.field, 42);
Required Methods§
sourcefn from_value(value: Value) -> VmResult<Self>
fn from_value(value: Value) -> VmResult<Self>
Try to convert to the given type, from the given value.
Object Safety§
This trait is not object safe.