diff --git a/abstutil/src/lib.rs b/abstutil/src/lib.rs index d71fa78f8c..6921122491 100644 --- a/abstutil/src/lib.rs +++ b/abstutil/src/lib.rs @@ -23,3 +23,16 @@ pub use crate::time::{ }; const PROGRESS_FREQUENCY_SECONDS: f64 = 0.2; + +// Thanks https://stackoverflow.com/a/49806368 +#[macro_export] +macro_rules! skip_fail { + ($res:expr) => { + match $res { + Some(val) => val, + None => { + continue; + } + } + }; +} diff --git a/popdat/src/psrc.rs b/popdat/src/psrc.rs index 5246298108..133f83c008 100644 --- a/popdat/src/psrc.rs +++ b/popdat/src/psrc.rs @@ -1,4 +1,4 @@ -use abstutil::{prettyprint_usize, FileWithProgress, Timer}; +use abstutil::{prettyprint_usize, FileWithProgress, Timer, skip_fail}; use geom::{Distance, Duration, GPSBounds, LonLat}; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; @@ -51,27 +51,15 @@ pub fn import_trips( let rec = rec?; // opcl - let from = if let Some(pt) = parcels.get(rec[15].trim_end_matches(".0")) { - *pt - } else { - continue; - }; + let from = *skip_fail!(parcels.get(rec[15].trim_end_matches(".0"))); // dpcl - let to = if let Some(pt) = parcels.get(rec[6].trim_end_matches(".0")) { - *pt - } else { - continue; - }; + let to = *skip_fail!(parcels.get(rec[6].trim_end_matches(".0"))); // deptm let depart_at = Duration::minutes(rec[4].trim_end_matches(".0").parse::()?); // mode - let mode = if let Some(m) = get_mode(&rec[13]) { - m - } else { - continue; - }; + let mode = skip_fail!(get_mode(&rec[13])); // opurp and dpurp let purpose = (get_purpose(&rec[16]), get_purpose(&rec[7]));