* update routeguide * update helloworld * depend on tonic beta.1 * Apply suggestions from code review Co-Authored-By: Lucio Franco <[email protected]> Co-authored-by: Lucio Franco <[email protected]>
34 lines
838 B
Rust
34 lines
838 B
Rust
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 file = File::open("examples/data/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()
|
|
}
|