aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-02-24 10:55:43 +0100
committerHarald Eilertsen <haraldei@anduin.net>2019-02-24 10:55:43 +0100
commitf08bbe736643beb3953199ae51610d4282d93476 (patch)
treec969da95dcf229c5eb5f067bc976f38edc2992fb
parent376d9c1896d6e23970071a6e9da01f9f0842c0d0 (diff)
downloadoslobike-f08bbe736643beb3953199ae51610d4282d93476.tar.gz
oslobike-f08bbe736643beb3953199ae51610d4282d93476.tar.bz2
oslobike-f08bbe736643beb3953199ae51610d4282d93476.zip
Handle the case where there's no availability data for a given station.
-rw-r--r--src/main.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 5e18bac..ffbeae2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,13 +29,20 @@ fn main() -> Result<(), Box<dyn Error>> {
let station_availability = api.station_availability()?;
for station in api.stations()? {
- let a = station_availability.iter().find(|s| s.id == station.id).unwrap();
- println!("{:>4} {:<32}: {:>2} bikes, {:>2} locks of {:>2} total",
- station.id,
- station.title,
- a.availability.bikes,
- a.availability.locks,
- station.number_of_locks);
+ if let Some(a) = station_availability.iter().find(|s| s.id == station.id) {
+ println!("{:>4} {:<32}: {:>2} bikes, {:>2} locks of {:>2} total",
+ station.id,
+ station.title,
+ a.availability.bikes,
+ a.availability.locks,
+ station.number_of_locks);
+ }
+ else {
+ println!("{:>4} {:<32}: No availability data, {:>2} total capacity",
+ station.id,
+ station.title,
+ station.number_of_locks);
+ }
}
Ok(())