Logo

Programming-Idioms

History of Idiom 91 > diff from v19 to v20

Edit summary for version 20 by programming-idioms.org:
[Rust] Comments emphasis

Version 19

2018-06-12, 17:56:10

Version 20

2018-08-03, 20:52:02

Idiom #91 Load JSON file into struct

Read from file data.json and write its content into object x.
Assume the JSON data is suitable for the type of x.

Idiom #91 Load JSON file into struct

Read from file data.json and write its content into object x.
Assume the JSON data is suitable for the type of x.

Imports
#[macro_use] extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
Imports
#[macro_use] extern crate serde_derive;
extern crate serde_json;
use std::fs::File;
Code
let x = ::serde_json::from_reader(File::open("data.json"))?;
Code
let x = ::serde_json::from_reader(File::open("data.json"))?;
Comments bubble
Requires x implements Deserialize from serde.
Serde is used to create an object from data, rather than populate an existing object.
Comments bubble
Requires x implements Deserialize from serde.
Serde is used to create an object from data, rather than populate an existing object.
Doc URL
https://docs.rs/serde_json/1.0.20/serde_json/fn.from_reader.html
Doc URL
https://docs.rs/serde_json/1.0.20/serde_json/fn.from_reader.html