Skip to Main Content
Rust Programming Cookbook
book

Rust Programming Cookbook

by Claus Matzinger
October 2019
Intermediate to advanced content levelIntermediate to advanced
444 pages
10h 37m
English
Packt Publishing
Content preview from Rust Programming Cookbook

How to do it...

Parsing is a multi-step process (but it's easy to do):

  1. First, let's add serde and its sub-crates to Cargo.toml. Open the file and add the following:
[dependencies]serde = "1"serde_json ="1"toml = "0.5"serde-pickle = "0.5"serde_derive = "1"
  1. Now, let's use the crates and see what they can do. We do this by creating tests that parse the same data from various formats, starting with JSON. In src/lib.rs, we replace the default tests module with the following:
#[macro_use]extern crate serde_json;#[cfg(test)]mod tests {    use serde_json::Value;    use serde_pickle as pickle;    use std::fs::File;    use toml;    #[test]    fn test_dynamic_json() {        let j = r#"{            "userid": 103609,            "verified": true,            "friendly_name": "Jason", "access_privileges": ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust Web Programming

Rust Web Programming

Maxwell Flitton
The Complete Rust Programming Reference Guide

The Complete Rust Programming Reference Guide

Rahul Sharma, Vesa Kaihlavirta, Claus Matzinger

Publisher Resources

ISBN: 9781789530667Supplemental Content