make Queue::reachable() iterator much more lean
This commit is contained in:
parent
6d1ced46e4
commit
e8351e73be
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue