Skip to content

Commit

Permalink
time: fix Timeout size_hint (#3902)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Jun 29, 2021
1 parent 8fa29cb commit 38204f5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tokio-stream/src/stream_ext/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,18 @@ impl<S: Stream> Stream for Timeout<S> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.stream.size_hint()
let (lower, upper) = self.stream.size_hint();

// The timeout stream may insert an error before and after each message
// from the underlying stream, but no more than one error between each
// message. Hence the upper bound is computed as 2x+1.

// Using a helper function to enable use of question mark operator.
fn twice_plus_one(value: Option<usize>) -> Option<usize> {
value?.checked_mul(2)?.checked_add(1)
}

(lower, twice_plus_one(upper))
}
}

Expand Down

0 comments on commit 38204f5

Please sign in to comment.