Refine examples.
This commit is contained in:
@@ -17,13 +17,13 @@ mod example {
|
||||
use rhai::{Dynamic, Engine, Map};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
struct Point {
|
||||
x: f64,
|
||||
y: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
struct MyStruct {
|
||||
a: i64,
|
||||
b: Vec<String>,
|
||||
@@ -71,6 +71,18 @@ mod example {
|
||||
// Convert the 'Dynamic' object map into 'MyStruct'
|
||||
let x: MyStruct = from_dynamic(&result).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
x,
|
||||
MyStruct {
|
||||
a: 42,
|
||||
b: vec!["hello".into(), "world".into()],
|
||||
c: true,
|
||||
d: Point {
|
||||
x: 123.456,
|
||||
y: 999.0,
|
||||
},
|
||||
}
|
||||
);
|
||||
println!("Deserialized to struct: {:#?}", x);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user