-
Open the Cargo.toml file that was generated earlier for you
- Under [dependencies], add the following line:
toml = "0.4.5"
- 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 TOML (https://crates.io/crates/toml), 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 toml.rs
-
Add the following code and run it with cargo run --bin toml:
1 #[macro_use]
2 extern crate serde_derive;
3 extern crate toml;
4
5 use std::io::{BufReader, BufWriter, Read, Seek, SeekFrom,
Write};
6 use std::fs::OpenOptions;
- These are the structures we are going to use throughout the recipe:
8 #[derive(Serialize, Deserialize)]
9 struct Preferences {
10 person: Person,
11 ...