diff options
author | stuebinm | 2022-02-09 02:51:59 +0100 |
---|---|---|
committer | stuebinm | 2022-02-09 02:51:59 +0100 |
commit | cd13c85c69cf761b2da84ad91af64d23a3568aa5 (patch) | |
tree | 4cbdbf6f348508ad7f70aa11450dccc8148ae0cb /src/zugportal.rs | |
parent | cf88935b5245daea51d2b513709b61a0e43483d6 (diff) |
existential types in rust are weird
… lots and lots of traits …
Diffstat (limited to '')
-rw-r--r-- | src/zugportal.rs | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/src/zugportal.rs b/src/zugportal.rs deleted file mode 100644 index f00cd04..0000000 --- a/src/zugportal.rs +++ /dev/null @@ -1,97 +0,0 @@ -/// implementation of traits to query zugportal.de -/// (available at least in the Munich S-Bahn, maybe other trains) - -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 Journey { - name: String, // the line's name, e.g. S 8 - no: i64, - stops: Vec<Stop> -} - - -#[derive(Deserialize, Debug)] -#[serde(rename_all="camelCase")] -pub struct Stop { - station: Station, - status: String, // one of "Normal", ...? - track: Track, - messages: Vec<String>, - arrival_time: Option<DepartureTime>, - departure_time: Option<DepartureTime> -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all="camelCase")] -struct Station { - eva_no: String, - name: String -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all="camelCase")] -struct Track { - target: String, - prediction: String -} - -#[derive(Deserialize, Debug)] -#[serde(rename_all="camelCase")] -struct DepartureTime { - target: DateTime<Utc>, - predicted: DateTime<Utc>, - time_type: String, // one of REAL, PREVIEW, ..? - diff: i64, // diff in minutes? - // NOTE: also sends predictedTimeInMs and targetTimeInMs; these might be unix times -} - -impl IsStation for Stop { - fn name(&self) -> &str { - &self.station.name - } - - fn scheduled_arrival(&self) -> Option<&chrono::DateTime<Utc>> { - self.arrival_time.as_ref().map(|t| &t.target) - } - - fn real_arrival(&self) -> Option<&chrono::DateTime<Utc>> { - self.arrival_time.as_ref().map(|t| &t.predicted) - } - - fn ds100(&self) -> &str { - "??" - } -} - -impl Journey { - pub fn guess_last_station(&self) -> Option<String> { - todo!() - // 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.name.clone(), - no: self.no.to_string().clone() - } - } - - pub fn trip(&self) -> crate::types::Trip<'_, Stop> { - crate::types::Trip(&self.stops) - } -} |