Skip to content

Commit

Permalink
Implement hashing for many basic enums
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Apr 5, 2024
1 parent b78f756 commit 3d02b4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Serialize for RouteType {
}

/// Describes if and how a traveller can board or alight the vehicle. See <https://gtfs.org/reference/static/#stop_timestxt> `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).
Expand Down Expand Up @@ -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 <https://developers.google.com/transit/gtfs/reference#routestxt,> not on <https://gtfs.org/reference/static/#routestxt>
#[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.
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'de> Deserialize<'de> for ContinuousPickupDropOff {
}

/// Describes if the stop time is exact or not. See <https://gtfs.org/reference/static/#stop_timestxt> `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
Expand Down Expand Up @@ -373,7 +373,7 @@ pub enum Exception {
}

/// Defines the direction of a [Trip], only for display, not for routing. See <https://gtfs.org/reference/static/#tripstxt> `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")]
Expand All @@ -384,7 +384,7 @@ pub enum DirectionType {
}

/// Is the [Trip] accessible with a bike. See <https://gtfs.org/reference/static/#tripstxt> `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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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].
Expand Down
3 changes: 2 additions & 1 deletion src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -33,7 +34,7 @@ impl<T: Type> Type for Arc<T> {
}

/// A calender describes on which days the vehicle runs. See <https://gtfs.org/reference/static/#calendartxt>
#[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")]
Expand Down

0 comments on commit 3d02b4e

Please sign in to comment.