xref: /tonic/examples/src/routeguide/data.rs (revision 3a5c66d5)
1 use serde::Deserialize;
2 use std::fs::File;
3 
4 #[derive(Debug, Deserialize)]
5 struct Feature {
6     location: Location,
7     name: String,
8 }
9 
10 #[derive(Debug, Deserialize)]
11 struct Location {
12     latitude: i32,
13     longitude: i32,
14 }
15 
16 #[allow(dead_code)]
17 pub fn load() -> Vec<crate::routeguide::Feature> {
18     let file =
19         File::open("tonic-examples/data/route_guide_db.json").expect("failed to open data file");
20 
21     let decoded: Vec<Feature> =
22         serde_json::from_reader(&file).expect("failed to deserialize features");
23 
24     decoded
25         .into_iter()
26         .map(|feature| crate::routeguide::Feature {
27             name: feature.name,
28             location: Some(crate::routeguide::Point {
29                 longitude: feature.location.longitude,
30                 latitude: feature.location.latitude,
31             }),
32         })
33         .collect()
34 }
35