From cd13c85c69cf761b2da84ad91af64d23a3568aa5 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Wed, 9 Feb 2022 02:51:59 +0100 Subject: existential types in rust are weird … lots and lots of traits … --- src/iceportal.rs | 99 -------------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 src/iceportal.rs (limited to 'src/iceportal.rs') diff --git a/src/iceportal.rs b/src/iceportal.rs deleted file mode 100644 index 3cb5e6f..0000000 --- a/src/iceportal.rs +++ /dev/null @@ -1,99 +0,0 @@ -use chrono::{DateTime, Utc}; -use serde::Deserialize; -use serde_json::Value; - -use crate::{serde::*, travelynx::TrainRef, types::IsStation}; - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct TripInfo { - trip: Trip, - connection: Option, - selected_route: Option, - active: Option -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Trip { - train_type: String, - vzn: String, // train number - // some position info here - actual_position: u64, // distance along track, presumably - stops: Vec -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct Stop { - info: StopInfo, - station: Station, - timetable: Timetable -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct StopInfo { - distance_from_start: u64, - position_status: String // one of "departed", "future", ... ? -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Station { - eva_nr: String, - name: String -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Timetable { - #[serde(deserialize_with = "option_naive_read_unixtime_db")] - scheduled_arrival_time: Option>, - #[serde(deserialize_with = "option_naive_read_unixtime_db")] - actual_arrival_time: Option> -} - -impl IsStation for Stop { - fn name(&self) -> &str { - &self.station.name - } - - fn scheduled_arrival(&self) -> Option<&chrono::DateTime> { - self.timetable.scheduled_arrival_time.as_ref() - } - - fn real_arrival(&self) -> Option<&chrono::DateTime> { - self.timetable.scheduled_arrival_time.as_ref() - } - - fn ds100(&self) -> &str { - "??" - } -} - -impl TripInfo { - pub fn guess_last_station(&self) -> Option { - let current_pos = self.trip.actual_position; - self - .trip - .stops - .iter() - .rev() - .map(|stop| (stop.info.distance_from_start, stop)) - .filter(|(dist, _)| dist <= ¤t_pos) - .next() - .map(|(_, stop)| stop.station.name.clone()) - } - - pub fn get_train_ref(&self) -> TrainRef { - TrainRef { - _type: self.trip.train_type.clone(), - no: self.trip.vzn.clone() - } - } - - pub fn trip(&self) -> crate::types::Trip<'_, Stop> { - crate::types::Trip(&self.trip.stops) - } -} -- cgit v1.2.3