Skip to main content

PrefetchExt

Trait PrefetchExt 

Source
pub trait PrefetchExt<T>:
    Iterator<Item = T>
    + Sized
    + Send
    + 'static
where T: Send + 'static,
{ // Provided methods fn prefetch(self, buffer_size: usize) -> PrefetchIterator<T> { ... } fn prefetch_unbounded(self) -> PrefetchIterator<T> { ... } }
Expand description

Extension trait for adding prefetching to iterators

This trait provides convenient methods for adding prefetching capabilities to any iterator that meets the requirements (Send + ’static items).

§Examples

use torsh_data::dataloader::prefetch::PrefetchExt;

let data = vec![1, 2, 3, 4, 5];
let prefetch_iter = data.into_iter().prefetch(2);

for item in prefetch_iter {
    // Process item while next items are being prefetched
}

Provided Methods§

Source

fn prefetch(self, buffer_size: usize) -> PrefetchIterator<T>

Add prefetching to the iterator

§Arguments
  • buffer_size - The size of the prefetch buffer
§Returns

A PrefetchIterator that will prefetch items from this iterator

Source

fn prefetch_unbounded(self) -> PrefetchIterator<T>

Add unbounded prefetching to the iterator

§Returns

A PrefetchIterator with unbounded buffering

§Warning

This can lead to excessive memory usage if the consumer is slower than the producer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I, T> PrefetchExt<T> for I
where I: Iterator<Item = T> + Send + 'static, T: Send + 'static,

Blanket implementation of PrefetchExt for all compatible iterators