-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathdata.rs
34 lines (29 loc) · 932 Bytes
/
data.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use serde::Deserialize;
use std::fs::File;
#[derive(Debug, Deserialize)]
struct Feature {
location: Location,
name: String,
}
#[derive(Debug, Deserialize)]
struct Location {
latitude: i32,
longitude: i32,
}
#[allow(dead_code)]
pub fn load() -> Vec<crate::routeguide::Feature> {
let data_dir = std::path::PathBuf::from_iter([std::env!("CARGO_MANIFEST_DIR"), "data"]);
let file = File::open(data_dir.join("route_guide_db.json")).expect("failed to open data file");
let decoded: Vec<Feature> =
serde_json::from_reader(&file).expect("failed to deserialize features");
decoded
.into_iter()
.map(|feature| crate::routeguide::Feature {
name: feature.name,
location: Some(crate::routeguide::Point {
longitude: feature.location.longitude,
latitude: feature.location.latitude,
}),
})
.collect()
}