Skip to content

Commit db4d422

Browse files
authored
Merge pull request #15 from ishantanu/clippy-updates
Clippy fixes
2 parents 155acab + 817176d commit db4d422

File tree

5 files changed

+74
-73
lines changed

5 files changed

+74
-73
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ Cargo.lock
1616

1717
# gitpod
1818
.gitpod.yml
19+
20+
# vscode
21+
.vscode/

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# TFL API Wrapper
22

3+
[![rust-clippy analyze](https://github.com/ishantanu/tfl-rust/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/ishantanu/tfl-rust/actions/workflows/rust-clippy.yml)
4+
35
A rust crate for using the [Transport for London (TFL) API](https://api.tfl.gov.uk).
46

57
*Note: Only the Line API is currently supported. Other APIs are work in progress*

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ pub use self::request::RequestBuilder;
44

55
pub mod client;
66
pub mod line;
7-
pub mod models;
87
pub mod linemodels;
8+
pub mod models;
99
pub mod request;

src/line.rs

+52-61
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ impl RouteRequestById<'_> {
5858
let mut lines: String = "".to_owned();
5959
for k in line {
6060
//k.line().to_string();
61-
if lines == "" {
62-
lines.push_str(k.line().into());
61+
if lines.is_empty() {
62+
lines.push_str(k.line());
6363
} else {
64-
lines.push_str(",");
65-
lines.push_str(k.line().into());
64+
lines.push(',');
65+
lines.push_str(k.line());
6666
}
6767
}
6868
self.parameters.lines = lines;
@@ -99,11 +99,11 @@ impl DisruptionByMode<'_> {
9999
let mut modes: String = "".to_owned();
100100
for k in mode {
101101
//k.line().to_string();
102-
if modes == "" {
103-
modes.push_str(k.mode().into());
102+
if modes.is_empty() {
103+
modes.push_str(k.mode());
104104
} else {
105-
modes.push_str(",");
106-
modes.push_str(k.mode().into());
105+
modes.push(',');
106+
modes.push_str(k.mode());
107107
}
108108
}
109109
self.parameters.modes = modes;
@@ -135,11 +135,11 @@ impl DisruptionByLines<'_> {
135135
let mut lines: String = "".to_owned();
136136
for k in line {
137137
//k.line().to_string();
138-
if lines == "" {
139-
lines.push_str(k.line().into());
138+
if lines.is_empty() {
139+
lines.push_str(k.line());
140140
} else {
141-
lines.push_str(",");
142-
lines.push_str(k.line().into());
141+
lines.push(',');
142+
lines.push_str(k.line());
143143
}
144144
}
145145
self.parameters.lines = lines;
@@ -171,11 +171,11 @@ impl ArrivalPredictionsByLines<'_> {
171171
let mut lines: String = "".to_owned();
172172
for k in line {
173173
//k.line().to_string();
174-
if lines == "" {
175-
lines.push_str(k.line().into());
174+
if lines.is_empty() {
175+
lines.push_str(k.line());
176176
} else {
177-
lines.push_str(",");
178-
lines.push_str(k.line().into());
177+
lines.push(',');
178+
lines.push_str(k.line());
179179
}
180180
}
181181
self.parameters.lines = lines;
@@ -206,15 +206,6 @@ impl RequestBuilder for ArrivalPredictionsByLinesStopPointID<'_> {
206206
self.get_parameters().lines,
207207
self.get_parameters().stop_point_id
208208
)
209-
} else if self.get_parameters().direction.is_some()
210-
&& self.get_parameters().destination_station_id.is_none()
211-
{
212-
format!(
213-
"/Line/{}/Arrivals/{}?{:?}",
214-
self.get_parameters().lines,
215-
self.get_parameters().stop_point_id,
216-
self.get_parameters().direction
217-
)
218209
} else {
219210
format!(
220211
"/Line/{}/Arrivals/{}?{:?}",
@@ -239,11 +230,11 @@ impl ArrivalPredictionsByLinesStopPointID<'_> {
239230
let mut lines: String = "".to_owned();
240231
for k in line {
241232
//k.line().to_string();
242-
if lines == "" {
243-
lines.push_str(k.line().into());
233+
if lines.is_empty() {
234+
lines.push_str(k.line());
244235
} else {
245-
lines.push_str(",");
246-
lines.push_str(k.line().into());
236+
lines.push(',');
237+
lines.push_str(k.line());
247238
}
248239
}
249240
self.parameters.lines = lines;
@@ -290,11 +281,11 @@ impl ListStationsByLines<'_> {
290281
let mut lines: String = "".to_owned();
291282
for k in line {
292283
//k.line().to_string();
293-
if lines == "" {
294-
lines.push_str(k.line().into());
284+
if lines.is_empty() {
285+
lines.push_str(k.line());
295286
} else {
296-
lines.push_str(",");
297-
lines.push_str(k.line().into());
287+
lines.push(',');
288+
lines.push_str(k.line());
298289
}
299290
}
300291
self.parameters.lines = lines;
@@ -411,11 +402,11 @@ impl ListLinesRoutesByModes<'_> {
411402
let mut modes: String = "".to_owned();
412403
for k in mode {
413404
//k.line().to_string();
414-
if modes == "" {
415-
modes.push_str(k.mode().into());
405+
if modes.is_empty() {
406+
modes.push_str(k.mode());
416407
} else {
417-
modes.push_str(",");
418-
modes.push_str(k.mode().into());
408+
modes.push(',');
409+
modes.push_str(k.mode());
419410
}
420411
}
421412
self.parameters.modes = modes;
@@ -530,11 +521,11 @@ impl ListLinesByID<'_> {
530521
let mut lines: String = "".to_owned();
531522
for k in line {
532523
//k.line().to_string();
533-
if lines == "" {
534-
lines.push_str(k.line().into());
524+
if lines.is_empty() {
525+
lines.push_str(k.line());
535526
} else {
536-
lines.push_str(",");
537-
lines.push_str(k.line().into());
527+
lines.push(',');
528+
lines.push_str(k.line());
538529
}
539530
}
540531
self.parameters.lines = lines;
@@ -566,11 +557,11 @@ impl ListLinesByModes<'_> {
566557
let mut modes: String = "".to_owned();
567558
for k in mode {
568559
//k.line().to_string();
569-
if modes == "" {
570-
modes.push_str(k.mode().into());
560+
if modes.is_empty() {
561+
modes.push_str(k.mode());
571562
} else {
572-
modes.push_str(",");
573-
modes.push_str(k.mode().into());
563+
modes.push(',');
564+
modes.push_str(k.mode());
574565
}
575566
}
576567
self.parameters.modes = modes;
@@ -646,11 +637,11 @@ impl LineStatusBetweenDates<'_> {
646637
let mut lines: String = "".to_owned();
647638
for k in line {
648639
//k.line().to_string();
649-
if lines == "" {
650-
lines.push_str(k.line().into());
640+
if lines.is_empty() {
641+
lines.push_str(k.line());
651642
} else {
652-
lines.push_str(",");
653-
lines.push_str(k.line().into());
643+
lines.push(',');
644+
lines.push_str(k.line());
654645
}
655646
}
656647
self.parameters.lines = lines;
@@ -716,11 +707,11 @@ impl LineStatusByModes<'_> {
716707
let mut modes: String = "".to_owned();
717708
for k in mode {
718709
//k.line().to_string();
719-
if modes == "" {
720-
modes.push_str(k.mode().into());
710+
if modes.is_empty() {
711+
modes.push_str(k.mode());
721712
} else {
722-
modes.push_str(",");
723-
modes.push_str(k.mode().into());
713+
modes.push(',');
714+
modes.push_str(k.mode());
724715
}
725716
}
726717
self.parameters.modes = modes;
@@ -771,11 +762,11 @@ impl LineStatusByIDs<'_> {
771762
let mut lines: String = "".to_owned();
772763
for k in line {
773764
//k.line().to_string();
774-
if lines == "" {
775-
lines.push_str(k.line().into());
765+
if lines.is_empty() {
766+
lines.push_str(k.line());
776767
} else {
777-
lines.push_str(",");
778-
lines.push_str(k.line().into());
768+
lines.push(',');
769+
lines.push_str(k.line());
779770
}
780771
}
781772
self.parameters.lines = lines;
@@ -922,11 +913,11 @@ impl SearchLineRoutesByQuery<'_> {
922913
let mut modes: String = "".to_owned();
923914
for k in mode {
924915
//k.line().to_string();
925-
if modes == "" {
926-
modes.push_str(k.mode().into());
916+
if modes.is_empty() {
917+
modes.push_str(k.mode());
927918
} else {
928-
modes.push_str(",");
929-
modes.push_str(k.mode().into());
919+
modes.push(',');
920+
modes.push_str(k.mode());
930921
}
931922
}
932923
self.parameters.modes = modes;

tests/tfl.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ mod tests {
5656
if l_str != l.line() {
5757
println!("Testing LineID: {} -> {}", l.line(), l_str);
5858
let lines: Vec<linemodels::LineID> = vec![l];
59-
let route = client.routes_by_line().line(lines).fetch().await.expect(
60-
format!("Failed whilst testing LineID: {} -> {}", l.line(), l_str).as_str(),
61-
);
59+
let route = client
60+
.routes_by_line()
61+
.line(lines)
62+
.fetch()
63+
.await
64+
.unwrap_or_else(|_| {
65+
panic!("Failed whilst testing LineID: {} -> {}", l.line(), l_str)
66+
});
6267
assert_eq!(route.name, l_str);
6368
}
6469
}
@@ -75,7 +80,7 @@ mod tests {
7580
.fetch()
7681
.await
7782
.unwrap();
78-
if disruptions.len() == 0 {
83+
if disruptions.is_empty() {
7984
assert!(disruptions.is_empty());
8085
} else {
8186
assert!(!disruptions.is_empty());
@@ -94,7 +99,7 @@ mod tests {
9499
.fetch()
95100
.await
96101
.unwrap();
97-
if disruptions.len() == 0 {
102+
if disruptions.is_empty() {
98103
assert!(disruptions.is_empty());
99104
} else {
100105
assert!(!disruptions.is_empty());
@@ -113,7 +118,7 @@ mod tests {
113118
.fetch()
114119
.await
115120
.unwrap();
116-
if arrivals.len() == 0 {
121+
if arrivals.is_empty() {
117122
assert!(arrivals.is_empty());
118123
} else {
119124
assert!(!arrivals.is_empty());
@@ -133,7 +138,7 @@ mod tests {
133138
.await
134139
.unwrap();
135140
println!("{:?}", predicted_arrivals);
136-
if predicted_arrivals.len() == 0 {
141+
if predicted_arrivals.is_empty() {
137142
assert!(predicted_arrivals.is_empty());
138143
} else {
139144
assert!(!predicted_arrivals.is_empty())
@@ -240,7 +245,7 @@ mod tests {
240245
.fetch()
241246
.await
242247
.unwrap();
243-
if line_statuses.len() == 0 {
248+
if line_statuses.is_empty() {
244249
assert!(line_statuses.is_empty())
245250
} else {
246251
assert!(!line_statuses.is_empty())
@@ -260,7 +265,7 @@ mod tests {
260265
.fetch()
261266
.await
262267
.unwrap();
263-
if line_statuses.len() == 0 {
268+
if line_statuses.is_empty() {
264269
assert!(line_statuses.is_empty())
265270
} else {
266271
assert!(!line_statuses.is_empty())
@@ -278,7 +283,7 @@ mod tests {
278283
.fetch()
279284
.await
280285
.unwrap();
281-
if line_statuses.len() == 0 {
286+
if line_statuses.is_empty() {
282287
assert!(line_statuses.is_empty())
283288
} else {
284289
assert!(!line_statuses.is_empty())
@@ -296,7 +301,7 @@ mod tests {
296301
.fetch()
297302
.await
298303
.unwrap();
299-
if line_statuses.len() == 0 {
304+
if line_statuses.is_empty() {
300305
assert!(line_statuses.is_empty())
301306
} else {
302307
assert!(!line_statuses.is_empty())

0 commit comments

Comments
 (0)