From 3d02b4ecf1b5e09bee4487a71afb56674431676e Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:18:00 -0700 Subject: [PATCH 1/3] Implement hashing for many basic enums --- src/enums.rs | 20 ++++++++++---------- src/objects.rs | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/enums.rs b/src/enums.rs index 408f3d1..e72a15d 100644 --- a/src/enums.rs +++ b/src/enums.rs @@ -167,7 +167,7 @@ impl Serialize for RouteType { } /// Describes if and how a traveller can board or alight the vehicle. See `pickup_type` and `dropoff_type` -#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default(bound = ""))] pub enum PickupDropOffType { /// Regularly scheduled pickup or drop off (default when empty). @@ -225,7 +225,7 @@ impl Serialize for PickupDropOffType { /// Indicates whether a rider can board the transit vehicle anywhere along the vehicle’s travel path /// /// Those values are only defined on not on -#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default(bound = ""))] pub enum ContinuousPickupDropOff { /// Continuous stopping pickup or drop off. @@ -281,7 +281,7 @@ impl<'de> Deserialize<'de> for ContinuousPickupDropOff { } /// Describes if the stop time is exact or not. See `timepoint` -#[derive(Debug, Derivative, Serialize, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Derivative, Serialize, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default)] pub enum TimepointType { /// Times are considered approximate @@ -373,7 +373,7 @@ pub enum Exception { } /// Defines the direction of a [Trip], only for display, not for routing. See `direction_id` -#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq, Eq, Hash)] pub enum DirectionType { /// Travel in one direction (e.g. outbound travel). #[serde(rename = "0")] @@ -384,7 +384,7 @@ pub enum DirectionType { } /// Is the [Trip] accessible with a bike. See `bikes_allowed` -#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default())] pub enum BikesAllowedType { /// No bike information for the trip @@ -447,7 +447,7 @@ pub enum PaymentMethod { } /// Defines if the [Frequency] is exact (the vehicle runs exactly every n minutes) or not -#[derive(Debug, Serialize, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Serialize, Copy, Clone, PartialEq, Eq, Hash)] pub enum ExactTimes { /// Frequency-based trips FrequencyBased = 0, @@ -474,7 +474,7 @@ impl<'de> Deserialize<'de> for ExactTimes { } /// Defines how many transfers can be done with on [FareAttribute] -#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default(bound = ""))] pub enum Transfers { /// Unlimited transfers are permitted @@ -521,7 +521,7 @@ impl Serialize for Transfers { } } /// Defines the type of a [StopTransfer] -#[derive(Debug, Serialize, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Serialize, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default)] pub enum TransferType { /// Recommended transfer point between routes @@ -569,7 +569,7 @@ impl<'de> Deserialize<'de> for TransferType { } /// Type of pathway between [from_stop] and [to_stop] -#[derive(Debug, Serialize, Deserialize, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default)] pub enum PathwayMode { /// A walkway @@ -599,7 +599,7 @@ pub enum PathwayMode { } /// Indicates in which direction the pathway can be used -#[derive(Debug, Serialize, Deserialize, Derivative, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, Derivative, Copy, Clone, PartialEq, Eq, Hash)] #[derivative(Default)] pub enum PathwayDirectionType { /// Unidirectional pathway, it can only be used from [from_stop_id] to [to_stop_id]. diff --git a/src/objects.rs b/src/objects.rs index f7ff02b..313113e 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -3,6 +3,7 @@ use crate::serde_helpers::*; use chrono::{Datelike, NaiveDate, Weekday}; use rgb::RGB8; +use std::hash::{Hash, Hasher}; use std::fmt; use std::sync::Arc; @@ -33,7 +34,7 @@ impl Type for Arc { } /// A calender describes on which days the vehicle runs. See -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)] pub struct Calendar { /// Unique technical identifier (not for the traveller) of this calendar #[serde(rename = "service_id")] From 8fa538de2ef7d6a100769669c5f89d2e72d2c3fd Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:19:57 -0700 Subject: [PATCH 2/3] Run cargo fmt --- Cargo.toml | 2 +- src/objects.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 913c1fa..62ff8fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "Read GTFS (public transit timetables) files" name = "gtfs-structures" -version = "0.41.2" +version = "0.41.3" authors = ["Tristram Gräbener ", "Antoine Desbordes "] repository = "https://github.com/rust-transit/gtfs-structure" license = "MIT" diff --git a/src/objects.rs b/src/objects.rs index 313113e..1fcc36f 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -3,8 +3,8 @@ use crate::serde_helpers::*; use chrono::{Datelike, NaiveDate, Weekday}; use rgb::RGB8; -use std::hash::{Hash, Hasher}; use std::fmt; +use std::hash::{Hash, Hasher}; use std::sync::Arc; /// Objects that have an identifier implement this trait From abbbcef5a437bd457bca106fd997c8cf190ad887 Mon Sep 17 00:00:00 2001 From: Kyler Chin <7539174+kylerchin@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:29:47 -0700 Subject: [PATCH 3/3] Remove unneeded Hasher import --- src/objects.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objects.rs b/src/objects.rs index 1fcc36f..387762d 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -4,7 +4,7 @@ use chrono::{Datelike, NaiveDate, Weekday}; use rgb::RGB8; use std::fmt; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; use std::sync::Arc; /// Objects that have an identifier implement this trait