1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use models::stop::StopTrip;
use std::cmp::Ordering;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
#[derive(Debug, Serialize, Clone)]
pub struct Trip {
pub uid: String,
pub route_id: String,
pub service_id: Option<String>,
pub headsign: Option<String>,
#[serde(skip_serializing)]
trip_id: String,
pub short_name: Option<String>,
pub direction_id: i32,
#[serde(skip_serializing_if = "Option::is_none")]
pub stop_sequence: Option<Vec<StopTrip>>,
#[serde(skip_serializing)]
feed_id: String,
}
impl Trip {
pub fn new(
uid: String,
route_id: String,
service_id: Option<String>,
headsign: Option<String>,
short_name: Option<String>,
direction_id: Option<i32>,
) -> Trip {
Trip {
uid,
route_id,
service_id,
trip_id: String::new(),
headsign,
short_name,
direction_id: match direction_id.is_some(){
true => {
direction_id.unwrap()
},
false => {
1
}
},
stop_sequence: Some(vec![]),
feed_id: String::new(),
}
}
pub fn set_id(&mut self, id: String) {
self.trip_id = id;
}
pub fn set_feed_id(&mut self, feed_id: String) {
self.feed_id = feed_id;
}
}
impl PartialEq for Trip {
fn eq(&self, other: &Trip) -> bool {
self.uid == other.uid
}
}
impl Hash for Trip {
fn hash<H: Hasher>(&self, state: &mut H) {
self.uid.hash(state);
}
}
impl Eq for Trip {}
impl Ord for Trip {
fn cmp(&self, other: &Self) -> Ordering {
self.uid.cmp(&other.uid)
}
}
impl PartialOrd for Trip {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}