Working with external data
Sometimes, we do not have complete control of our software stack. Usually, if you want to create a project, you will need to contact external data sources, which can lead to many issues, since achieving compatibility between your code and external APIs or sources can be difficult. Moreover, it can lead to performance loss, which we should avoid as much as possible. Let's check some efficient and easy-to-use solutions.
Data serialization and deserialization
When it comes to data serialization and deserialization in Rust, there is no doubt we are talking about serde (https://crates.io/crates/serde). Serde, from serialization and deserialization, gives us a unique tool to be able to transform our data structures to JSON, TOML, XML, or any other serializable format. Let's see how it works.
We start with a simple structure:
struct MyData { field1: String, field2: u32, field3: Vec<u8>, }
And we add serde
and serde_derive
as dependencies to our Cargo.toml...