diff --git a/model-builder/src/builder.rs b/model-builder/src/builder.rs index 5658eb00b..60608af93 100644 --- a/model-builder/src/builder.rs +++ b/model-builder/src/builder.rs @@ -140,11 +140,11 @@ impl<'a> ModelBuilder { /// .build(); /// # } /// ``` - pub fn calendar(mut self, id: &str, dates: &[impl IntoDate]) -> Self { + pub fn calendar(mut self, id: &str, dates: &[impl AsDate]) -> Self { { let mut c = self.collections.calendars.get_or_create(id); for d in dates { - c.dates.insert(d.into_date()); + c.dates.insert(d.as_date()); } } self @@ -168,7 +168,7 @@ impl<'a> ModelBuilder { /// .build(); /// # } /// ``` - pub fn default_calendar(self, dates: &[impl IntoDate]) -> Self { + pub fn default_calendar(self, dates: &[impl AsDate]) -> Self { self.calendar(DEFAULT_CALENDAR_ID, dates) } /// Add a new Calendar to the model @@ -239,25 +239,25 @@ impl IntoTime for &str { } } -pub trait IntoDate { - fn into_date(&self) -> Date; +pub trait AsDate { + fn as_date(&self) -> Date; } -impl IntoDate for Date { - fn into_date(&self) -> Date { +impl AsDate for Date { + fn as_date(&self) -> Date { *self } } -impl IntoDate for &Date { - fn into_date(&self) -> Date { +impl AsDate for &Date { + fn as_date(&self) -> Date { **self } } -impl IntoDate for &str { +impl AsDate for &str { // Note: if the string is not in the right format, this conversion will fail - fn into_date(&self) -> Date { + fn as_date(&self) -> Date { self.parse().expect("invalid date format") } } diff --git a/src/gtfs/mod.rs b/src/gtfs/mod.rs index e079ceb6b..5027f4024 100644 --- a/src/gtfs/mod.rs +++ b/src/gtfs/mod.rs @@ -423,7 +423,7 @@ struct Route { sort_order: Option, } -fn remove_stop_zones(model: Model) -> Result { +fn remove_stop_zones(model: Model) -> Collections { let mut collections = model.into_collections(); collections .stop_points @@ -442,14 +442,14 @@ fn remove_stop_zones(model: Model) -> Result { .all(|st| stop_point_ids.contains(&st.stop_point_idx)) }); - Ok(collections) + collections } /// Exports a `Model` to [GTFS](https://gtfs.org/reference/static) files /// in the given directory. /// see [NTFS to GTFS conversion](https://github.com/CanalTP/transit_model/blob/master/src/documentation/ntfs2gtfs.md) pub fn write>(model: Model, path: P) -> Result<()> { - let collections = remove_stop_zones(model)?; + let collections = remove_stop_zones(model); let model = Model::new(collections)?; let path = path.as_ref(); info!("Writing GTFS to {:?}", path); diff --git a/src/gtfs/read.rs b/src/gtfs/read.rs index e6fd5e033..60a6cf34d 100644 --- a/src/gtfs/read.rs +++ b/src/gtfs/read.rs @@ -1126,7 +1126,7 @@ fn make_ntfs_vehicle_journeys( routes: &CollectionWithId, datasets: &CollectionWithId, networks: &CollectionWithId, -) -> Result<(Vec, Vec)> { +) -> (Vec, Vec) { // there always is one dataset from config or a default one let (_, dataset) = datasets.iter().next().unwrap(); let mut vehicle_journeys: Vec = vec![]; @@ -1170,7 +1170,7 @@ fn make_ntfs_vehicle_journeys( } } - Ok((vehicle_journeys, trip_properties)) + (vehicle_journeys, trip_properties) } pub(in crate::gtfs) fn read_routes( @@ -1218,8 +1218,7 @@ where >fs_routes_collection, &collections.datasets, &collections.networks, - ) - .with_context(|_| format!("Error reading {:?}", "trips.txt"))?; + ); collections.vehicle_journeys = CollectionWithId::new(vehicle_journeys)?; collections.trip_properties = CollectionWithId::new(trip_properties)?; diff --git a/src/netex_france/calendars.rs b/src/netex_france/calendars.rs index 853801c5d..8cc2da333 100644 --- a/src/netex_france/calendars.rs +++ b/src/netex_france/calendars.rs @@ -37,13 +37,13 @@ impl<'a> CalendarExporter<'a> { .calendars .values() .map(|calendar| self.export_day_type(calendar)) - .collect::>>()?; + .collect::>(); let day_type_assignments_elements = self .model .calendars .values() .map(|calendar| self.export_day_type_assignement(calendar)) - .collect::>>()?; + .collect::>(); let uic_operating_periods_elements = self .model .calendars @@ -59,18 +59,18 @@ impl<'a> CalendarExporter<'a> { // Internal methods impl<'a> CalendarExporter<'a> { - fn export_day_type(&self, calendar: &'a Calendar) -> Result { - let element_builder = Element::builder(ObjectType::DayType.to_string()) + fn export_day_type(&self, calendar: &'a Calendar) -> Element { + Element::builder(ObjectType::DayType.to_string()) .attr( "id", Exporter::generate_id(&calendar.id, ObjectType::DayType), ) - .attr("version", "any"); - Ok(element_builder.build()) + .attr("version", "any") + .build() } - fn export_day_type_assignement(&self, calendar: &'a Calendar) -> Result { - let day_type_assignment = Element::builder(ObjectType::DayTypeAssignment.to_string()) + fn export_day_type_assignement(&self, calendar: &'a Calendar) -> Element { + Element::builder(ObjectType::DayTypeAssignment.to_string()) .attr( "id", Exporter::generate_id(&calendar.id, ObjectType::DayTypeAssignment), @@ -79,8 +79,7 @@ impl<'a> CalendarExporter<'a> { .attr("order", "0") .append(self.generate_operating_period_ref(&calendar.id)) .append(self.generate_day_type_ref(&calendar.id)) - .build(); - Ok(day_type_assignment) + .build() } fn export_uic_operating_period(&self, calendar: &'a Calendar) -> Result { diff --git a/src/netex_france/exporter.rs b/src/netex_france/exporter.rs index 44d292399..a7cd5b00c 100644 --- a/src/netex_france/exporter.rs +++ b/src/netex_france/exporter.rs @@ -183,7 +183,7 @@ impl<'a> Exporter<'a> { impl Exporter<'_> { // Include 'stop_frame' into a complete NeTEx XML tree with // 'PublicationDelivery' and 'dataObjects' - fn wrap_frame(&self, frame: Element, version_type: VersionType) -> Result { + fn wrap_frame(&self, frame: Element, version_type: VersionType) -> Element { let publication_timestamp = Element::builder("PublicationTimestamp") .ns("http://www.netex.org.uk/netex/") .append(self.timestamp.to_rfc3339()) @@ -196,7 +196,7 @@ impl Exporter<'_> { .ns("http://www.netex.org.uk/netex/") .append(frame) .build(); - let root = Element::builder("PublicationDelivery") + Element::builder("PublicationDelivery") .attr("version", format!("1.09:FR-NETEX_{}-2.1-1.0", version_type)) .attr("xmlns:siri", "http://www.siri.org.uk/siri") .attr("xmlns:core", "http://www.govtalk.gov.uk/core") @@ -209,8 +209,7 @@ impl Exporter<'_> { .append(publication_timestamp) .append(participant_ref) .append(data_objects) - .build(); - Ok(root) + .build() } fn generate_frame_id(&self, frame_type: FrameType, id: &str) -> String { @@ -244,7 +243,7 @@ impl Exporter<'_> { { let filepath = path.as_ref().join(NETEX_FRANCE_LINES_FILENAME); let file = File::create(&filepath)?; - let network_frames = self.create_networks_frames()?; + let network_frames = self.create_networks_frames(); let lines_frame = self.create_lines_frame()?; let companies_frame = self.create_companies_frame(); let frames = network_frames @@ -256,7 +255,7 @@ impl Exporter<'_> { &format!("NETEX_{}", VersionType::Lines), ); let composite_frame = Self::create_composite_frame(composite_frame_id, frames); - let netex = self.wrap_frame(composite_frame, VersionType::Lines)?; + let netex = self.wrap_frame(composite_frame, VersionType::Lines); let mut writer = ElementWriter::pretty(file); info!("Writing {:?}", &filepath); writer.write(&netex)?; @@ -264,9 +263,9 @@ impl Exporter<'_> { } // Returns a list of 'ServiceFrame' each containing a 'Network' - fn create_networks_frames(&self) -> Result> { + fn create_networks_frames(&self) -> Vec { let network_exporter = NetworkExporter::new(&self.model); - let network_elements = network_exporter.export()?; + let network_elements = network_exporter.export(); let frames = network_elements .into_iter() .zip(self.model.networks.values()) @@ -279,7 +278,7 @@ impl Exporter<'_> { .build() }) .collect(); - Ok(frames) + frames } // Returns a 'ServiceFrame' containing a list of 'Line' in 'lines' @@ -318,7 +317,7 @@ impl Exporter<'_> { let filepath = path.as_ref().join(NETEX_FRANCE_STOPS_FILENAME); let file = File::create(&filepath)?; let stop_frame = self.create_stops_frame()?; - let netex = self.wrap_frame(stop_frame, VersionType::Stops)?; + let netex = self.wrap_frame(stop_frame, VersionType::Stops); let mut writer = ElementWriter::pretty(file); info!("Writing {:?}", &filepath); writer.write(&netex)?; @@ -347,7 +346,7 @@ impl Exporter<'_> { let filepath = path.as_ref().join(NETEX_FRANCE_CALENDARS_FILENAME); let file = File::create(&filepath)?; let calendars_frame = self.create_calendars_frame()?; - let netex = self.wrap_frame(calendars_frame, VersionType::Calendars)?; + let netex = self.wrap_frame(calendars_frame, VersionType::Calendars); let mut writer = ElementWriter::pretty(file); info!("Writing {:?}", &filepath); writer.write(&netex)?; @@ -398,7 +397,7 @@ impl Exporter<'_> { let filepath = path.as_ref().join(NETEX_FRANCE_TRANSFERS_FILENAME); let file = File::create(&filepath)?; let transfers_frame = self.create_transfers_frame()?; - let netex = self.wrap_frame(transfers_frame, VersionType::Transfers)?; + let netex = self.wrap_frame(transfers_frame, VersionType::Transfers); let mut writer = ElementWriter::pretty(file); info!("Writing {:?}", &filepath); writer.write(&netex)?; @@ -461,7 +460,7 @@ impl Exporter<'_> { let filepath = network_path.as_ref().join(file_name); let file = File::create(&filepath)?; let offer_frame = self.create_offer_frame(&offer_exporter, line_idx)?; - let netex = self.wrap_frame(offer_frame, VersionType::Schedule)?; + let netex = self.wrap_frame(offer_frame, VersionType::Schedule); let mut writer = ElementWriter::pretty(file); info!("Writing {:?}", &filepath); writer.write(&netex)?; diff --git a/src/netex_france/networks.rs b/src/netex_france/networks.rs index 8758ad0b9..f9355a8f7 100644 --- a/src/netex_france/networks.rs +++ b/src/netex_france/networks.rs @@ -15,7 +15,7 @@ use crate::{ netex_france::exporter::{Exporter, ObjectType}, objects::{Line, Network}, - Model, Result, + Model, }; use minidom::{Element, Node}; @@ -28,7 +28,7 @@ impl<'a> NetworkExporter<'a> { pub fn new(model: &'a Model) -> Self { NetworkExporter { model } } - pub fn export(&self) -> Result> { + pub fn export(&self) -> Vec { self.model .networks .values() @@ -39,7 +39,7 @@ impl<'a> NetworkExporter<'a> { // Internal methods impl<'a> NetworkExporter<'a> { - fn export_network(&self, network: &'a Network) -> Result { + fn export_network(&self, network: &'a Network) -> Element { let element_builder = Element::builder(ObjectType::Network.to_string()) .attr( "id", @@ -54,7 +54,7 @@ impl<'a> NetworkExporter<'a> { .filter(|line| line.network_id == network.id) .map(|line| self.generate_line_ref(line)); let element_builder = element_builder.append(Exporter::create_members(line_ref_elements)); - Ok(element_builder.build()) + element_builder.build() } fn generate_name(&self, network: &'a Network) -> Element { diff --git a/src/ntfs/read.rs b/src/ntfs/read.rs index d2c5f92c9..2604e2a76 100644 --- a/src/ntfs/read.rs +++ b/src/ntfs/read.rs @@ -713,7 +713,7 @@ mod tests { use crate::test_utils::*; use pretty_assertions::assert_eq; - fn generate_minimal_ntfs>(path: P) -> Result<()> { + fn generate_minimal_ntfs>(path: P) { let commercial_modes_content = "commercial_mode_id,commercial_mode_name\n\ commercial_mode_1,My Commercial Mode 1"; @@ -771,8 +771,6 @@ mod tests { create_file_with_content(path, "trips.txt", trips_content); create_file_with_content(path, "calendar.txt", calendar_content); create_file_with_content(path, "stop_times.txt", stop_times_content); - - Ok(()) } fn make_collection(path: &path::Path) -> Collections {