pub struct Lookahead { /* private fields */ }Expand description
A cursor that runs a fixed distance ahead of a scan, handing out each item that many items before the scan consumes it, so the caller can prefetch what the item’s work reads.
Call Self::advance with the scan’s unconsumed tail before consuming its next item. It
returns every item exactly once, in scan order, and the first call returns the scan’s first
distance + 1 items so the pipeline starts full.
Over a scan of eight items at distance two, the call before each item returns:
before item 0 remaining [0 1 2 3 4 5 6 7] returns [0 1 2] (fills the window)
before item 1 remaining [1 2 3 4 5 6 7] returns [3]
before item 2 remaining [2 3 4 5 6 7] returns [4]
...
before item 5 remaining [5 6 7] returns [7]
before item 6 remaining [6 7] returns [] (the tail is spent)Implementations§
Source§impl Lookahead
impl Lookahead
Sourcepub const fn new(distance: usize) -> Self
pub const fn new(distance: usize) -> Self
A cursor over one scan that runs distance items ahead.
Sourcepub fn advance<'a, T>(&mut self, remaining: &'a [T]) -> &'a [T]
pub fn advance<'a, T>(&mut self, remaining: &'a [T]) -> &'a [T]
The items within distance of the scan’s next item that no earlier call returned.
remaining holds the scan’s unconsumed tail, in order.
§Panics
Panics if remaining starts more than distance + 1 items before the first item no
earlier call returned.