Refine examples.

This commit is contained in:
Stephen Chung
2020-12-26 15:41:41 +08:00
parent dc4e52e795
commit db9dcd1bcc
5 changed files with 33 additions and 19 deletions

View File

@@ -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);
}
}