pub trait FromValue: 'static + Sized {
// Required method
fn from_value(value: Value) -> Result<Self, RuntimeError>;
}
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) -> Result<Self, RuntimeError>
fn from_value(value: Value) -> Result<Self, RuntimeError>
Try to convert to the given type, from the given 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.