37 lines
894 B
Rust
37 lines
894 B
Rust
use std::collections::HashMap;
|
|
use std::fs::File;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct Aircraft {
|
|
pub icao24: String,
|
|
pub registration: String,
|
|
pub manufacturername: String,
|
|
pub model: String,
|
|
pub owner: String,
|
|
}
|
|
|
|
pub struct Aircrafts {
|
|
data: HashMap<String, Aircraft>,
|
|
}
|
|
|
|
impl Aircrafts {
|
|
pub fn load(file: &str) -> Self {
|
|
let mut rdr = csv::Reader::from_reader(File::open(file).unwrap());
|
|
let mut data = HashMap::new();
|
|
for result in rdr.deserialize() {
|
|
let aircraft: Aircraft = result.unwrap();
|
|
data.insert(aircraft.icao24.clone(), aircraft);
|
|
}
|
|
println!("Loaded aircraft database with {} entries", data.len());
|
|
|
|
Aircrafts {
|
|
data,
|
|
}
|
|
}
|
|
|
|
pub fn find<'s>(&'s self, hex: &str) -> Option<&'s Aircraft> {
|
|
self.data.get(hex)
|
|
}
|
|
}
|