Skip to content

Commit ef6a077

Browse files
committed
Fix clippy warnings
1 parent b7da807 commit ef6a077

File tree

7 files changed

+33
-47
lines changed

7 files changed

+33
-47
lines changed

src/archive.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use std;
21
use std::fs;
32
use std::io;
43
#[cfg(unix)]
54
use std::os::unix::fs::PermissionsExt;
6-
use zip;
75

86
pub fn extract_zip<T: io::Read + io::Seek>(
97
archive: &mut zip::ZipArchive<T>,
@@ -15,15 +13,15 @@ pub fn extract_zip<T: io::Read + io::Seek>(
1513

1614
{
1715
let comment = file.comment();
18-
if comment.len() > 0 {
16+
if !comment.is_empty() {
1917
println!(" File comment: {}", comment);
2018
}
2119
}
2220

2321
let perms = convert_permissions(file.unix_mode());
2422

2523
// also suspicious but why not?
26-
if (&*file.name()).ends_with("/") {
24+
if (&*file.name()).ends_with('/') {
2725
create_directory(&outpath, perms);
2826
} else {
2927
write_file(&mut file, &outpath, perms);
@@ -34,10 +32,7 @@ pub fn extract_zip<T: io::Read + io::Seek>(
3432

3533
#[cfg(unix)]
3634
fn convert_permissions(mode: Option<u32>) -> Option<fs::Permissions> {
37-
match mode {
38-
Some(mode) => Some(fs::Permissions::from_mode(mode)),
39-
None => None,
40-
}
35+
mode.map(fs::Permissions::from_mode)
4136
}
4237
#[cfg(not(unix))]
4338
fn convert_permissions(_mode: Option<u32>) -> Option<fs::Permissions> {
@@ -71,10 +66,7 @@ fn sanitize_filename(filename: &str) -> std::path::PathBuf {
7166

7267
std::path::Path::new(no_null_filename)
7368
.components()
74-
.filter(|component| match *component {
75-
std::path::Component::Normal(..) => true,
76-
_ => false,
77-
})
69+
.filter(|component| matches!(*component, std::path::Component::Normal(..)))
7870
.fold(std::path::PathBuf::new(), |mut path, ref cur| {
7971
path.push(cur.as_os_str());
8072
path

src/feed.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use csv;
2-
use serde;
31
use std::fs::File;
42
use std::path::Path;
53
use tempfile::{Builder, TempDir};
6-
use zip;
74

85
use super::archive::extract_zip;
96
use super::{
@@ -41,7 +38,7 @@ impl LocalFeedProvider {
4138

4239
impl FeedProvider for LocalFeedProvider {
4340
fn path(&self) -> &str {
44-
return &self.path;
41+
&self.path
4542
}
4643
}
4744

@@ -60,7 +57,7 @@ impl ZipFeedProvider {
6057
zip::ZipArchive::new(File::open(zipfile).map_err(|e| Error::Feed(format!("{}", e)))?)
6158
.map_err(|e| Error::Feed(format!("{}", e)))?;
6259
extract_zip(&mut zip, dir.path()).map_err(|e| Error::Feed(format!("{}", e)))?;
63-
Ok(ZipFeedProvider { dir: dir })
60+
Ok(ZipFeedProvider { dir })
6461
}
6562
}
6663

@@ -85,7 +82,7 @@ impl FeedReader<ZipFeedProvider> {
8582
impl<P: FeedProvider> FeedReader<P> {
8683
pub fn from_provider(provider: P) -> Self {
8784
FeedReader {
88-
provider: provider,
85+
provider,
8986
builder: csv::ReaderBuilder::new(),
9087
}
9188
}
@@ -164,6 +161,6 @@ impl<P: FeedProvider> FeedReader<P> {
164161
Ok(reader) => reader,
165162
Err(e) => return Err(Error::Csv(path, e)),
166163
};
167-
Ok(GTFSIterator::new(reader, &path)?)
164+
GTFSIterator::new(reader, &path)
168165
}
169166
}

src/gtfs/gtfs.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use super::error::Error;
22
use csv::{
33
DeserializeError, DeserializeRecordsIntoIter, ErrorKind, Position, Reader, StringRecord,
44
};
5-
use serde;
6-
use std;
75

86
pub struct GTFSIterator<R, T>
97
where
@@ -40,19 +38,19 @@ where
4038
};
4139
Ok(GTFSIterator {
4240
iter: reader.into_deserialize(),
43-
headers: headers,
41+
headers,
4442
filename: filename.to_string(),
4543
})
4644
}
4745

4846
fn wrap_fielderror(&self, err: &DeserializeError, position: &Option<Position>) -> Error {
49-
let fieldname = match err.field() {
50-
Some(field_pos) => Some(match self.headers.get(field_pos as usize) {
47+
let fieldname = err
48+
.field()
49+
.map(|field_pos| match self.headers.get(field_pos as usize) {
5150
Some(field) => field.to_string(),
52-
None => format!("field {}", field_pos).to_string(),
53-
}),
54-
None => None,
55-
};
51+
None => format!("field {}", field_pos),
52+
});
53+
5654
// TODO:: What if position.line() is None?
5755
Error::FieldError(
5856
String::clone(&self.filename),

src/gtfs/parse.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use chrono::{Duration, NaiveDate};
2-
use serde;
32
use serde::Deserializer;
43

54
pub fn deserialize_dow_field<'de, D>(deserializer: D) -> Result<bool, D::Error>

src/transit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,9 @@ pub struct TimeOffset {
435435
impl TimeOffset {
436436
pub fn from_hms(hours: u32, minutes: u32, seconds: u32) -> TimeOffset {
437437
TimeOffset {
438-
hours: hours,
439-
minutes: minutes,
440-
seconds: seconds,
438+
hours,
439+
minutes,
440+
seconds,
441441
}
442442
}
443443

tests/feed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn test_read_feed_with_reader_options() {
66
feed.builder().delimiter(b';').trim(Trim::All);
77

88
for result in feed.stops().unwrap() {
9-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
9+
assert!(result.is_ok(), "{}", result.err().unwrap());
1010
}
1111
}
1212

@@ -15,7 +15,7 @@ fn test_read_zipfiles_with_feed() {
1515
let feed = FeedReader::from_zip("./examples/good_feed.zip").unwrap();
1616

1717
for result in feed.stops().unwrap() {
18-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
18+
assert!(result.is_ok(), "{}", result.err().unwrap());
1919
}
2020
}
2121

tests/read_gtfs.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn test_read_agencies() {
88
let iter: GTFSIterator<_, Agency> =
99
GTFSIterator::from_path("./examples/good_feed/agency.txt").unwrap();
1010
for result in iter {
11-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
11+
assert!(result.is_ok(), "{}", result.err().unwrap());
1212
}
1313
}
1414

@@ -17,7 +17,7 @@ fn test_read_stops() {
1717
let iter: GTFSIterator<_, Stop> =
1818
GTFSIterator::from_path("./examples/good_feed/stops.txt").unwrap();
1919
for result in iter {
20-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
20+
assert!(result.is_ok(), "{}", result.err().unwrap());
2121
}
2222
}
2323

@@ -26,7 +26,7 @@ fn test_read_routes() {
2626
let iter: GTFSIterator<_, Route> =
2727
GTFSIterator::from_path("./examples/good_feed/routes.txt").unwrap();
2828
for result in iter {
29-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
29+
assert!(result.is_ok(), "{}", result.err().unwrap());
3030
}
3131
}
3232

@@ -35,7 +35,7 @@ fn test_read_trips() {
3535
let iter: GTFSIterator<_, Trip> =
3636
GTFSIterator::from_path("./examples/good_feed/trips.txt").unwrap();
3737
for result in iter {
38-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
38+
assert!(result.is_ok(), "{}", result.err().unwrap());
3939
}
4040
}
4141

@@ -44,7 +44,7 @@ fn test_read_stop_times() {
4444
let iter: GTFSIterator<_, StopTime> =
4545
GTFSIterator::from_path("./examples/good_feed/stop_times.txt").unwrap();
4646
for result in iter {
47-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
47+
assert!(result.is_ok(), "{}", result.err().unwrap());
4848
}
4949
}
5050

@@ -53,7 +53,7 @@ fn test_read_calendar() {
5353
let iter: GTFSIterator<_, Calendar> =
5454
GTFSIterator::from_path("./examples/good_feed/calendar.txt").unwrap();
5555
for result in iter {
56-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
56+
assert!(result.is_ok(), "{}", result.err().unwrap());
5757
}
5858
}
5959

@@ -62,7 +62,7 @@ fn test_read_calendar_dates() {
6262
let iter: GTFSIterator<_, CalendarDate> =
6363
GTFSIterator::from_path("./examples/good_feed/calendar_dates.txt").unwrap();
6464
for result in iter {
65-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
65+
assert!(result.is_ok(), "{}", result.err().unwrap());
6666
}
6767
}
6868

@@ -71,7 +71,7 @@ fn test_read_fare_attributes() {
7171
let iter: GTFSIterator<_, FareAttribute> =
7272
GTFSIterator::from_path("./examples/good_feed/fare_attributes.txt").unwrap();
7373
for result in iter {
74-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
74+
assert!(result.is_ok(), "{}", result.err().unwrap());
7575
}
7676
}
7777

@@ -80,7 +80,7 @@ fn test_read_fare_rules() {
8080
let iter: GTFSIterator<_, FareRule> =
8181
GTFSIterator::from_path("./examples/good_feed/fare_rules.txt").unwrap();
8282
for result in iter {
83-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
83+
assert!(result.is_ok(), "{}", result.err().unwrap());
8484
}
8585
}
8686

@@ -89,7 +89,7 @@ fn test_read_shapes() {
8989
let iter: GTFSIterator<_, ShapePoint> =
9090
GTFSIterator::from_path("./examples/good_feed/shapes.txt").unwrap();
9191
for result in iter {
92-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
92+
assert!(result.is_ok(), "{}", result.err().unwrap());
9393
}
9494
}
9595

@@ -98,7 +98,7 @@ fn test_read_frequencies() {
9898
let iter: GTFSIterator<_, Frequency> =
9999
GTFSIterator::from_path("./examples/good_feed/frequencies.txt").unwrap();
100100
for result in iter {
101-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
101+
assert!(result.is_ok(), "{}", result.err().unwrap());
102102
}
103103
}
104104

@@ -107,7 +107,7 @@ fn test_read_transfers() {
107107
let iter: GTFSIterator<_, Transfer> =
108108
GTFSIterator::from_path("./examples/good_feed/transfers.txt").unwrap();
109109
for result in iter {
110-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
110+
assert!(result.is_ok(), "{}", result.err().unwrap());
111111
}
112112
}
113113

@@ -116,6 +116,6 @@ fn test_read_feed_info() {
116116
let iter: GTFSIterator<_, FeedInfo> =
117117
GTFSIterator::from_path("./examples/good_feed/feed_info.txt").unwrap();
118118
for result in iter {
119-
assert!(result.is_ok(), format!("{}", result.err().unwrap()));
119+
assert!(result.is_ok(), "{}", result.err().unwrap());
120120
}
121121
}

0 commit comments

Comments
 (0)