Skip to content

Commit

Permalink
fix: msrv
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyKitkat committed Mar 23, 2024
1 parent e795b43 commit ba09ce0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3453,10 +3453,10 @@ impl<S: Stream> Stream for Chunks<S> {
fn size_hint(&self) -> (usize, Option<usize>) {
let (lower, upper) = self.stream.size_hint();
let len = self.items.len();
let lower = lower.saturating_add(len).div_ceil(self.cap);
let lower = div_ceil_(lower.saturating_add(len), self.cap);
let upper = upper
.and_then(|u| u.checked_add(len))
.map(|u| u.div_ceil(self.cap));
.map(|u| div_ceil_(u, self.cap));
(lower, upper)
}
}
Expand Down Expand Up @@ -3534,10 +3534,10 @@ impl<S: Stream<Item = Result<T, E>>, T, E> Stream for TryChunks<S, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
let (lower, upper) = self.stream.size_hint();
let len = self.items.len();
let lower = lower.saturating_add(len).div_ceil(self.cap);
let lower = div_ceil_(lower.saturating_add(len), self.cap);
let upper = upper
.and_then(|u| u.checked_add(len))
.map(|u| u.div_ceil(self.cap));
.map(|u| div_ceil_(u, self.cap));
(lower, upper)
}
}
Expand Down Expand Up @@ -3565,3 +3565,18 @@ impl<T, E: fmt::Display> fmt::Display for TryChunksError<T, E> {

#[cfg(feature = "std")]
impl<T, E: fmt::Debug + fmt::Display> std::error::Error for TryChunksError<T, E> {}

// int::div_cell is stable in rust 1.73 and above
// since currently our msrv is 1.60
// we just copy the code from std
// and rename to div_cell_ to avoid conflict
#[cfg(feature = "alloc")]
fn div_ceil_(a: usize, b: usize) -> usize {
let d = a / b;
let r = a % b;
if r > 0 && b > 0 {
d + 1
} else {
d
}
}

0 comments on commit ba09ce0

Please sign in to comment.