mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
use a skip_fail macro in loops
This commit is contained in:
parent
dad1c170ed
commit
7b4b0b20b7
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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]));
|
||||
|
Loading…
Reference in New Issue
Block a user