From 80a4af9f0a6f7e3bd2d8254f8bc8475ca73b8980 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 1 Feb 2022 17:41:56 +0100 Subject: 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. --- src/types.rs | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/types.rs') 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 -where - D: Deserializer<'de>, -{ - let ts = ::deserialize(d)?; - Ok(NaiveDateTime::from_timestamp(ts, 0)) -} -fn option_naive_read_unixtime<'de, D>(d: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - match ::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, } -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); +pub struct Trip<'a, S: IsStation> (pub &'a Vec); + 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 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() -- cgit v1.2.3