Serialization basics with Serde
The de facto standard for all things serialization in Rust is the Serde framework. All the other recipes in this chapter are going to use it to some extent. In order to make you familiar with the Serde way of doing things, we are going to rewrite the last recipe using it. Later in the chapter, we will learn in detail how Serde works in order to implement idiomatic deserialization into a homemade format.
How to do it...
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 calledserde_csv.rs...