Skip to content

Commit dca911b

Browse files
committed
Fix clippy: option_map_unit_fn
1 parent d822b68 commit dca911b

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

src/diskio/immediate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl ImmediateUnpacker {
1313
}
1414

1515
impl Executor for ImmediateUnpacker {
16-
fn dispatch(&mut self, mut item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
16+
fn dispatch(&mut self, mut item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
1717
perform(&mut item);
1818
Box::new(Some(item).into_iter())
1919
}

src/diskio/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,24 @@ pub trait Executor {
122122
/// During overload situations previously queued items may
123123
/// need to be completed before the item is accepted:
124124
/// consume the returned iterator.
125-
fn execute(&mut self, mut item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
125+
fn execute(&mut self, mut item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
126126
item.start = precise_time_s();
127127
self.dispatch(item)
128128
}
129129

130130
/// Actually dispatch a operation.
131131
/// This is called by the default execute() implementation and
132132
/// should not be called directly.
133-
fn dispatch(&mut self, item: Item) -> Box<dyn '_ + Iterator<Item = Item>>;
133+
fn dispatch(&mut self, item: Item) -> Box<dyn Iterator<Item = Item> + '_>;
134134

135135
/// Wrap up any pending operations and iterate over them.
136136
/// All operations submitted before the join will have been
137137
/// returned either through ready/complete or join once join
138138
/// returns.
139-
fn join(&mut self) -> Box<dyn '_ + Iterator<Item = Item>>;
139+
fn join(&mut self) -> Box<dyn Iterator<Item = Item> + '_>;
140140

141141
/// Iterate over completed items.
142-
fn completed(&mut self) -> Box<dyn '_ + Iterator<Item = Item>>;
142+
fn completed(&mut self) -> Box<dyn Iterator<Item = Item> + '_>;
143143
}
144144

145145
/// Trivial single threaded IO to be used from executors.

src/diskio/threaded.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a> Threaded<'a> {
8989
}
9090

9191
impl<'a> Executor for Threaded<'a> {
92-
fn dispatch(&mut self, item: Item) -> Box<dyn '_ + Iterator<Item = Item>> {
92+
fn dispatch(&mut self, item: Item) -> Box<dyn Iterator<Item = Item> + '_> {
9393
// Yield any completed work before accepting new work - keep memory
9494
// pressure under control
9595
// - return an iterator that runs until we can submit and then submits
@@ -100,7 +100,7 @@ impl<'a> Executor for Threaded<'a> {
100100
})
101101
}
102102

103-
fn join(&mut self) -> Box<dyn '_ + Iterator<Item = Item>> {
103+
fn join(&mut self) -> Box<dyn Iterator<Item = Item> + '_> {
104104
// Some explanation is in order. Even though the tar we are reading from (if
105105
// any) will have had its FileWithProgress download tracking
106106
// completed before we hit drop, that is not true if we are unwinding due to a
@@ -115,16 +115,14 @@ impl<'a> Executor for Threaded<'a> {
115115
// items, and the download tracker's progress is confounded with
116116
// actual handling of data today, we synthesis a data buffer and
117117
// pretend to have bytes to deliver.
118-
self.notify_handler
119-
.map(|handler| handler(Notification::DownloadFinished));
120-
self.notify_handler
121-
.map(|handler| handler(Notification::DownloadPushUnits("iops")));
122118
let mut prev_files = self.n_files.load(Ordering::Relaxed);
123-
self.notify_handler.map(|handler| {
119+
if let Some(handler) = self.notify_handler {
120+
handler(Notification::DownloadFinished);
121+
handler(Notification::DownloadPushUnits("iops"));
124122
handler(Notification::DownloadContentLengthReceived(
125123
prev_files as u64,
126-
))
127-
});
124+
));
125+
}
128126
if prev_files > 50 {
129127
println!("{} deferred IO operations", prev_files);
130128
}
@@ -139,14 +137,15 @@ impl<'a> Executor for Threaded<'a> {
139137
prev_files = current_files;
140138
current_files = self.n_files.load(Ordering::Relaxed);
141139
let step_count = prev_files - current_files;
142-
self.notify_handler
143-
.map(|handler| handler(Notification::DownloadDataReceived(&buf[0..step_count])));
140+
if let Some(handler) = self.notify_handler {
141+
handler(Notification::DownloadDataReceived(&buf[0..step_count]));
142+
}
144143
}
145144
self.pool.join();
146-
self.notify_handler
147-
.map(|handler| handler(Notification::DownloadFinished));
148-
self.notify_handler
149-
.map(|handler| handler(Notification::DownloadPopUnits));
145+
if let Some(handler) = self.notify_handler {
146+
handler(Notification::DownloadFinished);
147+
handler(Notification::DownloadPopUnits);
148+
}
150149
// close the feedback channel so that blocking reads on it can
151150
// complete. send is atomic, and we know the threads completed from the
152151
// pool join, so this is race-free. It is possible that try_iter is safe
@@ -167,7 +166,7 @@ impl<'a> Executor for Threaded<'a> {
167166
})
168167
}
169168

170-
fn completed(&mut self) -> Box<dyn '_ + Iterator<Item = Item>> {
169+
fn completed(&mut self) -> Box<dyn Iterator<Item = Item> + '_> {
171170
Box::new(JoinIterator {
172171
iter: self.rx.try_iter(),
173172
consume_sentinel: true,

0 commit comments

Comments
 (0)