summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs30
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()