summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/types.rs b/src/types.rs
index 482025a..5afbad2 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -87,6 +87,12 @@ pub struct Train {
id: String
}
+impl std::fmt::Display for Train {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{} {}", self._type, self.no)
+ }
+}
+
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Status {
@@ -105,31 +111,28 @@ pub struct Ds100 {
inner: String
}
-pub struct Trip<'a, 'i, S: IsStation>(
- pub &'i mut dyn std::iter::Iterator<Item = &'a S>
-);
+/// this type is a little silly, but apparently there's no better way
+/// to 'forget' what the concrete type is than re-constructing the vec?
+pub struct Trip<'a>(Vec<&'a dyn IsStation>);
-impl std::fmt::Display for Train {
+impl std::fmt::Display for Trip<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{} {}", self._type, self.no)
+ if self.0.len() != 0 {
+ self
+ .0
+ .iter()
+ .map(|stop| stop.to_fancy_string())
+ .for_each(|l| writeln!(f, " {}\n ↓", l).unwrap());
+ }
+ Ok(())
}
}
-// #[allow(unstable_name_collisions)]
-impl<S: IsStation> std::fmt::Display for Trip<'_, '_, S> {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- 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(())
+/// with this, you sometimes have to write (&self.stops).into()
+/// yay for reference syntax!
+impl<'a, S: IsStation + 'a> From<&'a Vec<S>> for Trip<'a> {
+ fn from(from: &'a Vec<S>) -> Self {
+ Trip(from.iter().map(|s| s as &dyn IsStation).collect())
}
}
@@ -154,7 +157,7 @@ impl std::fmt::Display for Status {
.unwrap_or("".to_string())
.green(),
self.from_station.to_fancy_string(),
- Trip(&mut self.intermediate_stops.iter()),
+ Trip::from(&self.intermediate_stops),
self
.to_station
.as_ref()