use a skip_fail macro in loops

This commit is contained in:
Dustin Carlino 2019-05-23 16:24:26 -07:00
parent dad1c170ed
commit 7b4b0b20b7
2 changed files with 17 additions and 16 deletions

View File

@ -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;
}
}
};
}

View File

@ -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::<usize>()?);
// 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]));