make Queue::reachable() iterator much more lean

This commit is contained in:
tali 2023-04-12 15:49:53 -04:00
parent 6d1ced46e4
commit e8351e73be
1 changed files with 3 additions and 2 deletions

View File

@ -38,8 +38,9 @@ impl<'a, T: Copy> Queue<'a, T> {
/// Yields the next pieces available to use from the queue. The returned iterator may
/// be empty, and may yield at most 2 elements.
pub fn reachable(&self) -> impl Iterator<Item = T> {
let front = self.next.get(0).copied();
[front, self.hold].into_iter().flatten()
let mut hold = self.hold;
let mut front = self.next.get(0).copied();
core::iter::from_fn(move || hold.take().or_else(|| front.take()))
}
}