Skip to main content

PrefetchBuffer

Struct PrefetchBuffer 

Source
pub struct PrefetchBuffer<S: AsyncRowSource> { /* private fields */ }
Expand description

Wraps an AsyncRowSource and provides a synchronous RowSource view.

The buffer caches fetched rows in an LRU cache (capacity max_rows). On a cache miss it returns a placeholder row of Cell::Empty values and enqueues the row index for background prefetch. Callers are expected to drive the prefetch loop by calling flush_pending in an async context (e.g. a Tokio task or a wasm_bindgen_futures::spawn_local closure).

§Placeholder row

A cache miss returns N Cell::Empty cells where N is column_defs().len(). Renderers may style such cells as loading placeholders (spinner, shimmer, etc.).

§Thread safety

The inner state is wrapped in Arc<Mutex<_>> so PrefetchBuffer is Send + Sync and can be shared across threads or with async runtimes.

Implementations§

Source§

impl<S: AsyncRowSource> PrefetchBuffer<S>

Source

pub fn new(source: S, max_rows: usize, prefetch_ahead: usize) -> Self

Create a new buffer wrapping source.

  • max_rows: maximum number of rows to hold in the LRU cache.
  • prefetch_ahead: number of rows ahead of the viewport to enqueue for prefetch when request_prefetch is called.
Source

pub fn request_prefetch(&self, start: usize, viewport_rows: usize)

Request that rows [start, start + viewport_rows + prefetch_ahead) be prefetched.

Non-cached rows are enqueued internally; call flush_pending in an async context to actually perform the fetches.

Source

pub async fn flush_pending(&self) -> usize

Drive the prefetch loop, fetching all pending rows and storing them in the cache.

Should be called from an async context (e.g. a spawned task). Returns the number of rows successfully fetched in this call.

Source

pub fn store_row(&self, index: usize, cells: Vec<Cell>)

Store a single already-fetched row directly into the cache.

Useful for callers that manage their own prefetch executor.

Source

pub fn invalidate(&self)

Invalidate the entire cache (e.g. after a source mutation).

The next call to RowSource::row will trigger fresh prefetch requests for every accessed row.

Source

pub fn cached_count(&self) -> usize

Number of rows currently held in the cache.

Source

pub fn is_cached(&self, index: usize) -> bool

True if the given row index is in the cache.

Source

pub fn source(&self) -> &S

Access the underlying async source.

Trait Implementations§

Source§

impl<S: AsyncRowSource> Clone for PrefetchBuffer<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: AsyncRowSource> RowSource for PrefetchBuffer<S>

Source§

fn row_count(&self) -> usize

Returns the total number of rows in the data source.
Source§

fn column_defs(&self) -> &[ColumnDef]

Returns the column definitions (name + preferred width).
Source§

fn row(&self, index: usize) -> Vec<Cell>

Returns the cells for row at the given index.
Source§

fn row_height(&self, index: usize) -> f32

Per-row height in logical pixels. Read more
Source§

fn footer(&self) -> Option<Vec<Cell>>

Optional footer (aggregate) row displayed below the data rows. Read more
Source§

fn set_cell( &mut self, _row: usize, _col: usize, _value: Cell, ) -> Result<(), TableError>

Attempt to set a cell value in the source. Read more
Source§

fn children(&self, _row: usize) -> Option<Vec<usize>>

Optional children of a row, enabling tree / grouped tables. Read more
Source§

fn indent_level(&self, _row: usize) -> usize

Indent level for a row in a tree / grouped table. Read more

Auto Trait Implementations§

§

impl<S> Freeze for PrefetchBuffer<S>

§

impl<S> RefUnwindSafe for PrefetchBuffer<S>
where S: RefUnwindSafe,

§

impl<S> Send for PrefetchBuffer<S>
where S: Sync,

§

impl<S> Sync for PrefetchBuffer<S>
where S: Sync,

§

impl<S> Unpin for PrefetchBuffer<S>

§

impl<S> UnsafeUnpin for PrefetchBuffer<S>

§

impl<S> UnwindSafe for PrefetchBuffer<S>
where S: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.