-
Open the Cargo.toml file that was generated earlier for you.
- Under [dependencies], add the following lines:
serde = "1.0.24"
serde_derive = "1.0.24"
- If you haven't done so already in the last recipe, add the following line as well:
csv = "1.0.0-beta.5"
- If you want, you can go to the crates.io web pages for Serde (https://crates.io/crates/serde), serde_derive (https://crates.io/crates/serde_derive), and CSV (https://crates.io/crates/csv) to check for the newest versions and use those ones instead.
-
In the bin folder, create a file called serde_csv.rs.
-
Add the following code and run it with cargo run --bin serde_csv:
1 extern crate csv;
2 extern crate serde;
3 #[macro_use]
4 extern crate serde_derive;
5
6 use std::io::{BufReader, BufWriter, Read, Seek, SeekFrom,
Write};
7 use std::fs::OpenOptions;
8
9 #[derive(Serialize, Deserialize)]
10 struct Planet {
11 name: String,
12 radius...