Skip to content

Commit 5a0f7da

Browse files
authored
Merge pull request #1332 from autumnontape/size_hint
fix size_hint implementations in driver iterators
2 parents ce32b1d + 96d4379 commit 5a0f7da

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ when upgrading from a version of rust-sdl2 to another.
1414

1515
[PR #1318](https://github.com/Rust-SDL2/rust-sdl2/pull/1318) Add NV12, NV21 to PixelFormatEnum
1616

17+
[PR #1332](https://github.com/Rust-SDL2/rust-sdl2/pull/1332) Fix `size_hint` implementations for `{audio,video,render}::DriverIterator`
18+
1719
### v0.35.2
1820

1921
[PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks

src/sdl2/audio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ impl Iterator for DriverIterator {
372372

373373
#[inline]
374374
fn size_hint(&self) -> (usize, Option<usize>) {
375-
let l = self.length as usize;
376-
(l, Some(l))
375+
let remaining = (self.length - self.index) as usize;
376+
(remaining, Some(remaining))
377377
}
378378
}
379379

src/sdl2/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2576,8 +2576,8 @@ impl Iterator for DriverIterator {
25762576

25772577
#[inline]
25782578
fn size_hint(&self) -> (usize, Option<usize>) {
2579-
let l = self.length as usize;
2580-
(l, Some(l))
2579+
let remaining = (self.length - self.index) as usize;
2580+
(remaining, Some(remaining))
25812581
}
25822582
}
25832583

src/sdl2/video.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2012,8 +2012,8 @@ impl Iterator for DriverIterator {
20122012

20132013
#[inline]
20142014
fn size_hint(&self) -> (usize, Option<usize>) {
2015-
let l = self.length as usize;
2016-
(l, Some(l))
2015+
let remaining = (self.length - self.index) as usize;
2016+
(remaining, Some(remaining))
20172017
}
20182018
}
20192019

0 commit comments

Comments
 (0)