Add the serialization example.
This commit is contained in:
parent
39c4dffe36
commit
243f4ece9f
11
examples/02-serialization/Cargo.toml
Normal file
11
examples/02-serialization/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "serialization"
|
||||
version = "0.1.0"
|
||||
authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1"
|
||||
|
||||
[dependencies.splines]
|
||||
version = "0.1"
|
||||
features = ["serialization"]
|
30
examples/02-serialization/src/main.rs
Normal file
30
examples/02-serialization/src/main.rs
Normal file
@ -0,0 +1,30 @@
|
||||
#[macro_use] extern crate serde_json;
|
||||
extern crate splines;
|
||||
|
||||
use serde_json::{Value, from_value};
|
||||
use splines::Spline;
|
||||
|
||||
fn main() {
|
||||
let value = json!{
|
||||
[
|
||||
{
|
||||
"t": 0,
|
||||
"interpolation": "linear",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"t": 1,
|
||||
"interpolation": { "step": 0.5 },
|
||||
"value": 1
|
||||
},
|
||||
{
|
||||
"t": 5,
|
||||
"interpolation": "cosine",
|
||||
"value": 10
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
let spline = from_value::<Spline<f32>>(value);
|
||||
println!("{:?}", spline);
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"01-hello-world"
|
||||
"01-hello-world",
|
||||
"02-serialization"
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
|
Loading…
Reference in New Issue
Block a user