diff options
author | stuebinm | 2022-02-01 17:41:56 +0100 |
---|---|---|
committer | stuebinm | 2022-02-01 17:42:59 +0100 |
commit | 80a4af9f0a6f7e3bd2d8254f8bc8475ca73b8980 (patch) | |
tree | a2077ce6d328f2b94d0394fa1590c0cc5feac6fe /src/types.rs | |
parent | aacb2d78a4a97e3e8d7fdff4c06cba8be5f3139f (diff) |
display iceportal itinery & stops
I'm pretty sure something in parsing the times is broken, since this
train is currently /also/ broken I have absolutely no idea what the
correct ones would be and don't have the energy to dig further into
this.
Diffstat (limited to 'src/types.rs')
-rw-r--r-- | src/types.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/types.rs b/src/types.rs index 1efd9c1..2d8d189 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,7 +2,8 @@ use serde::{Deserialize, Deserializer}; use chrono::NaiveDateTime; use colored::*; -use itertools::Itertools; + +use crate::serde::*; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -31,24 +32,6 @@ where } -fn naive_read_unixtime<'de, D>(d: D) -> Result<NaiveDateTime, D::Error> -where - D: Deserializer<'de>, -{ - let ts = <i64>::deserialize(d)?; - Ok(NaiveDateTime::from_timestamp(ts, 0)) -} -fn option_naive_read_unixtime<'de, D>(d: D) -> Result<Option<NaiveDateTime>, D::Error> -where - D: Deserializer<'de>, -{ - match <i64>::deserialize(d) { - Ok(ts) => - Ok(Some(NaiveDateTime::from_timestamp(ts, 0))), - Err(_) => Ok(None) - } -} - #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -64,7 +47,9 @@ pub struct Stop { real_departure: Option<NaiveDateTime>, } -trait IsStation { + + +pub trait IsStation { fn name (&self) -> &str; fn scheduled_arrival (&self) -> Option<&NaiveDateTime>; fn real_arrival (&self) -> Option<&NaiveDateTime>; @@ -157,7 +142,8 @@ pub struct Ds100 { inner: String, } -struct Trip<'a> (&'a Vec<Stop>); +pub struct Trip<'a, S: IsStation> (pub &'a Vec<S>); + impl std::fmt::Display for Train { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -166,7 +152,7 @@ impl std::fmt::Display for Train { } #[allow(unstable_name_collisions)] -impl std::fmt::Display for Trip<'_> { +impl<S: IsStation> std::fmt::Display for Trip<'_, S> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.0.len() != 0 { self.0.iter() |