Skip to content

Commit

Permalink
[feature] use the new Iterator::skip_error
Browse files Browse the repository at this point in the history
  • Loading branch information
woshilapin committed May 10, 2021
1 parent 6f08bfd commit 3de811e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ relational_types = "2"
rust_decimal = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
skip_error = { version = "1", features = ["log"] }
skip_error = { version = "1", features = ["log"], git = "https://github.com/CanalTP/skip_error", branch = "skip_error_iter" }
tempfile = "3"
thiserror = "1"
typed_index_collection = "2"
Expand Down
13 changes: 6 additions & 7 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use failure::{bail, format_err, Error};
use geo::{LineString, Point};
use log::{info, warn, Level as LogLevel};
use serde::Deserialize;
use skip_error::skip_error_and_log;
use skip_error::{skip_error_and_log, SkipError};
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::convert::TryFrom;
use typed_index_collection::{impl_id, Collection, CollectionWithId, Idx};
Expand Down Expand Up @@ -1103,12 +1103,11 @@ fn make_ntfs_vehicle_journeys(
});
id_incr += 1;
}
for t in trips {
vehicle_journeys.push(skip_error_and_log!(
t.to_ntfs_vehicle_journey(routes, dataset, &property_id, networks,),
LogLevel::Warn
));
}
trips
.iter()
.map(|t| t.to_ntfs_vehicle_journey(routes, dataset, &property_id, networks))
.skip_error_and_log(LogLevel::Warn)
.for_each(|vj| vehicle_journeys.push(vj));
}

(vehicle_journeys, trip_properties)
Expand Down
15 changes: 6 additions & 9 deletions src/read_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
use failure::{bail, format_err, ResultExt};
use log::{info, Level as LogLevel};
use serde::Deserialize;
use skip_error::skip_error_and_log;
use std::path;
use std::path::{Path, PathBuf};
use std::{collections::BTreeMap, io::Read};
Expand Down Expand Up @@ -268,14 +267,12 @@ where
.flexible(true)
.trim(csv::Trim::All)
.from_reader(reader);
let mut objects: Vec<O> = vec![];
for object in rdr.deserialize() {
let object: O = skip_error_and_log!(
object.with_context(|_| format!("Error reading {:?}", path)),
LogLevel::Warn
);
objects.push(object);
}
use skip_error::SkipError;
let objects = rdr
.deserialize()
.map(|object| object.with_context(|_| format!("Error reading {:?}", path)))
.skip_error_and_log(LogLevel::Warn)
.collect();
Ok(objects)
}
}
Expand Down

0 comments on commit 3de811e

Please sign in to comment.