-
Open the Cargo.toml file that has been generated earlier for you
- Under [dependencies], add the following line:
serde_json = "1.0.8"
- If you haven't done so already, add the following lines as well:
serde = "1.0.24"
serde_derive = "1.0.24"
- If you want, you can go to the crates.io web pages for serde_json (https://crates.io/crates/serde_json), Serde (https://crates.io/crates/serde), and serde_derive (https://crates.io/crates/serde_derive) to check for the newest versions and use those ones instead
-
In the bin folder, create a file called json.rs
-
Add the following code and run it with cargo run --bin json:
1 extern crate serde;
2 extern crate serde_json;
3
4 #[macro_use]
5 extern crate serde_derive;
6
7 use std::io::{BufReader, BufWriter, Read, Seek, SeekFrom,
Write};
8 use std::fs::OpenOptions;
- These are the structures we are going to use throughout the recipe:
10 #[derive(Serialize, Deserialize)]
11...