Rust crates: custom serde deserializers (Twitch live stream 2023-02-13)
In this video, we continued our exploration of the serde and the serde-json crates. In particular, we improved our deserialization logic by adding some custom deserializers.
- Previous episode in the series: https://youtu.be/rqUH1Dnz8Ho
- Serde & Serde JSON (to parse JSON data): https://serde.rs/
The code is available here: https://github.com/lmammino/rust-lastfm
Chapters:
00:00:00 Intro & Recap from the last stream
00:03:40 Defining a custom ImageSet struct
00:06:00 Refactoring code into submodules
00:07:35 Custom deserialization function using serde deserialize_with
00:20:30 Handling missing fields with serde errors
00:29:16 Writing a test for our custom deserializer
00:31:40 Using the serde json!() macro
00:35:00 Debugging our test
00:38:00 Deserializing by implementing the Deserialize trait directly
00:41:13 Cleaning up and adding more tests
00:50:10 Adding support for now_playing field using deserialize_with
00:58:00 Using serde rename annotation
01:02:55 Testing our solution
01:03:20 Using the serde default annotation
01:05:30 Making the date field optional
01:07:10 Committing and wrapping up
Huge thanks to WGaffa & Altos__ for all the help given during this stream :)
To see the next episodes live check out our Twitch channel: https://twitch.tv/loige
Chat with me on Twitter at https://twitter.com/loige
#rust #json #serde