Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tech] Update to clippy 1.50.0 #744

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions model-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/gtfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ struct Route {
sort_order: Option<u32>,
}

fn remove_stop_zones(model: Model) -> Result<Collections> {
fn remove_stop_zones(model: Model) -> Collections {
let mut collections = model.into_collections();
collections
.stop_points
Expand All @@ -442,14 +442,14 @@ fn remove_stop_zones(model: Model) -> Result<Collections> {
.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<P: AsRef<Path>>(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);
Expand Down
7 changes: 3 additions & 4 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ fn make_ntfs_vehicle_journeys(
routes: &CollectionWithId<Route>,
datasets: &CollectionWithId<objects::Dataset>,
networks: &CollectionWithId<objects::Network>,
) -> Result<(Vec<objects::VehicleJourney>, Vec<objects::TripProperty>)> {
) -> (Vec<objects::VehicleJourney>, Vec<objects::TripProperty>) {
// there always is one dataset from config or a default one
let (_, dataset) = datasets.iter().next().unwrap();
let mut vehicle_journeys: Vec<objects::VehicleJourney> = vec![];
Expand Down Expand Up @@ -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<H>(
Expand Down Expand Up @@ -1218,8 +1218,7 @@ where
&gtfs_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)?;

Expand Down
19 changes: 9 additions & 10 deletions src/netex_france/calendars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl<'a> CalendarExporter<'a> {
.calendars
.values()
.map(|calendar| self.export_day_type(calendar))
.collect::<Result<Vec<Element>>>()?;
.collect::<Vec<Element>>();
let day_type_assignments_elements = self
.model
.calendars
.values()
.map(|calendar| self.export_day_type_assignement(calendar))
.collect::<Result<Vec<Element>>>()?;
.collect::<Vec<Element>>();
let uic_operating_periods_elements = self
.model
.calendars
Expand All @@ -59,18 +59,18 @@ impl<'a> CalendarExporter<'a> {

// Internal methods
impl<'a> CalendarExporter<'a> {
fn export_day_type(&self, calendar: &'a Calendar) -> Result<Element> {
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<Element> {
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),
Expand All @@ -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<Element> {
Expand Down
25 changes: 12 additions & 13 deletions src/netex_france/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element> {
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())
Expand All @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -256,17 +255,17 @@ 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)?;
Ok(())
}

// Returns a list of 'ServiceFrame' each containing a 'Network'
fn create_networks_frames(&self) -> Result<Vec<Element>> {
fn create_networks_frames(&self) -> Vec<Element> {
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())
Expand All @@ -279,7 +278,7 @@ impl Exporter<'_> {
.build()
})
.collect();
Ok(frames)
frames
}

// Returns a 'ServiceFrame' containing a list of 'Line' in 'lines'
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down
8 changes: 4 additions & 4 deletions src/netex_france/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::{
netex_france::exporter::{Exporter, ObjectType},
objects::{Line, Network},
Model, Result,
Model,
};
use minidom::{Element, Node};

Expand All @@ -28,7 +28,7 @@ impl<'a> NetworkExporter<'a> {
pub fn new(model: &'a Model) -> Self {
NetworkExporter { model }
}
pub fn export(&self) -> Result<Vec<Element>> {
pub fn export(&self) -> Vec<Element> {
self.model
.networks
.values()
Expand All @@ -39,7 +39,7 @@ impl<'a> NetworkExporter<'a> {

// Internal methods
impl<'a> NetworkExporter<'a> {
fn export_network(&self, network: &'a Network) -> Result<Element> {
fn export_network(&self, network: &'a Network) -> Element {
let element_builder = Element::builder(ObjectType::Network.to_string())
.attr(
"id",
Expand All @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions src/ntfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ mod tests {
use crate::test_utils::*;
use pretty_assertions::assert_eq;

fn generate_minimal_ntfs<P: AsRef<path::Path>>(path: P) -> Result<()> {
fn generate_minimal_ntfs<P: AsRef<path::Path>>(path: P) {
let commercial_modes_content = "commercial_mode_id,commercial_mode_name\n\
commercial_mode_1,My Commercial Mode 1";

Expand Down Expand Up @@ -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 {
Expand Down