summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs64
1 files changed, 19 insertions, 45 deletions
diff --git a/src/types.rs b/src/types.rs
index c1c949a..482025a 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,9 +1,10 @@
use serde::{Deserialize, Deserializer};
-use chrono::{DateTime, Local, Utc};
+use chrono::{DateTime, Utc};
use colored::*;
use crate::serde::*;
+use crate::traits::IsStation;
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
@@ -44,38 +45,6 @@ pub struct Stop {
real_departure: Option<DateTime<Utc>>
}
-pub trait IsStation {
- fn name(&self) -> &str;
- fn scheduled_arrival(&self) -> Option<&DateTime<Utc>>;
- fn real_arrival(&self) -> Option<&DateTime<Utc>>;
- fn ds100(&self) -> &str;
-
- fn to_fancy_string(&self) -> String {
- format!(
- "{} {} – {} ({})",
- self
- .real_arrival() // chrono's API for timezones is expressive, but reads like c++ …
- .map(|t| <DateTime<Local>>::from(*t).time().to_string())
- .unwrap_or("??:??:??".to_string())
- .blue(),
- {
- let delay = match (self.real_arrival(), self.scheduled_arrival()) {
- (Some(a), Some(s)) => (a.time() - s.time()).num_minutes(),
- _ => 0
- };
- let text = format!("({:+})", delay);
- if delay > 0 {
- text.red()
- } else {
- text.green()
- }
- },
- self.ds100().red(),
- self.name()
- )
- }
-}
-
impl IsStation for Station {
fn name(&self) -> &str {
&self.name
@@ -136,7 +105,9 @@ pub struct Ds100 {
inner: String
}
-pub struct Trip<'a, S: IsStation>(pub &'a Vec<S>);
+pub struct Trip<'a, 'i, S: IsStation>(
+ pub &'i mut dyn std::iter::Iterator<Item = &'a S>
+);
impl std::fmt::Display for Train {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -144,17 +115,20 @@ impl std::fmt::Display for Train {
}
}
-#[allow(unstable_name_collisions)]
-impl<S: IsStation> std::fmt::Display for Trip<'_, S> {
+// #[allow(unstable_name_collisions)]
+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()
- .map(|stop| stop.to_fancy_string())
- // .intersperse(" ↓".to_string())
- .for_each(|l| writeln!(f, " {}\n ↓", l).unwrap());
- }
+ todo!();
+ // self.0.map(|stop| stop.to_fancy_string())
+ // .for_each(|l| writeln!(f, " {}\n ↓", l).unwrap());
+ // if self.0.len() != 0 {
+ // self
+ // .0
+ // .iter()
+ // .map(|stop| stop.to_fancy_string())
+ // // .intersperse(" ↓".to_string())
+ // .for_each(|l| writeln!(f, " {}\n ↓", l).unwrap());
+ // }
Ok(())
}
}
@@ -180,7 +154,7 @@ impl std::fmt::Display for Status {
.unwrap_or("".to_string())
.green(),
self.from_station.to_fancy_string(),
- Trip(&self.intermediate_stops),
+ Trip(&mut self.intermediate_stops.iter()),
self
.to_station
.as_ref()