xref: /tonic/examples/src/routeguide/data.rs (revision da92dbf8)
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 = File::open("examples/data/route_guide_db.json").expect("failed to open data file");
19 
20     let decoded: Vec<Feature> =
21         serde_json::from_reader(&file).expect("failed to deserialize features");
22 
23     decoded
24         .into_iter()
25         .map(|feature| crate::routeguide::Feature {
26             name: feature.name,
27             location: Some(crate::routeguide::Point {
28                 longitude: feature.location.longitude,
29                 latitude: feature.location.latitude,
30             }),
31         })
32         .collect()
33 }
34