Skip to main content

PagedModel

Struct PagedModel 

Source
pub struct PagedModel { /* private fields */ }
Expand description

A grid model (for densa_widgets::DataGrid) of rows fetched a page at a time from a PageSource: a table too large to hold, such as a query engine’s result over files of billions of rows. The grid shows only some rows, and the model fetches their pages and one on each side, on a thread of its own, so the window never waits; rows not yet fetched show empty until they arrive.

A click on a column title asks the source for its rows in that order. Cells are formatted as in ArrowTable; columns are sized by the first rows and widened when later numbers no longer fit. Rows have no keys: a selection is a position. A copy of selected rows holds those among them that are held (GridModel::copy_rows): selecting all of a billion rows copies those held, which can be runs far apart. On a 32-bit target, rows past usize::MAX are not shown.

Costs: a frame whose pages are held allocates nothing; one that asks for pages or takes them in does. Dropping the model ends its thread once the source’s current call returns.

Implementations§

Source§

impl PagedModel

Source

pub fn new( schema: SchemaRef, source: impl PageSource, wake: impl Fn() + Send + 'static, ) -> Result<Self>

A model of the rows source gives, with schema (every page’s columns), fetched on a thread of its own in pages of 256 rows.

wake is called on that thread each time it sends something back (rows, a count, a failure), and possibly once after the model is dropped: give it move || { waker.wake(); } with a densa_window::Waker, so the window paints what came. If wake panics, the thread stops (FetchError::Stopped).

§Errors

The thread could not be started.

Source

pub fn with_options( schema: SchemaRef, source: impl PageSource, wake: impl Fn() + Send + 'static, options: PageOptions, ) -> Result<Self>

As new, paging as options say.

§Errors

The thread could not be started.

Source

pub fn schema(&self) -> &SchemaRef

The schema of the rows.

Source

pub fn row_count(&self) -> Option<u64>

How many rows there are, once the source counted them: None until then, and after a count failed.

Source

pub fn error(&self) -> Option<&FetchError>

Why rows are missing: the source’s last failure (to count, to give rows, rows that came back short), cleared by retry, refresh and sorting; or that the thread fetching pages stopped, which nothing clears.

Source

pub fn is_fetched(&self, row: usize) -> bool

Whether row’s page is held as the source gives it now (not one kept from before a refresh until it is fetched again).

Source

pub fn pages_held(&self) -> usize

How many pages are held.

Source

pub fn page_rows(&self) -> usize

Rows a page holds.

Source

pub fn retry(&mut self)

Asks again for what failed: the pages shown that the source failed to give, or the count (not one on its way). Pages held stay.

Source

pub fn refresh(&mut self)

Counts the rows and fetches the pages shown again: for when the source’s data changed. The rows held are shown until their pages are back, and the count until the new one is. Sorting fetches the pages of the new order by itself.

Source

pub fn set_decimals( &mut self, column: usize, decimals: Option<usize>, ) -> Result<(), TableError>

As ArrowTable::set_decimals: floating-point values of column with decimals fixed decimal places (None: the shortest exact form). A column sized by the pages is sized again from those held, as now printed; the grid takes in the new width.

§Errors

TableError::NoSuchColumn if there is no such column.

Source

pub fn set_column_chars( &mut self, column: usize, chars: usize, ) -> Result<(), TableError>

As ArrowTable::set_column_chars: column is chars characters wide (1 to CELL_BYTES), longer text cut to fit ending in …, and pages no longer size it; the grid takes in the new width.

§Errors

TableError::NoSuchColumn if there is no such column.

Trait Implementations§

Source§

impl Debug for PagedModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GridModel for PagedModel

Source§

fn copy_rows(&self, rows: Range<usize>) -> Vec<Range<usize>>

The rows of rows held, in runs: a copy holds no rows not fetched.

Source§

fn sort(&mut self, column: usize, order: SortOrder) -> bool

Asks the source for its rows sorted by column; false for a column the schema does not have, whose name an earlier column has (the source sorts by name), or that the source cannot sort by (PageSource::can_sort).

Source§

fn columns(&self) -> &[Column]

The columns, left to right.
Source§

fn rows(&self) -> usize

How many rows there are.
Source§

fn cell( &self, row: usize, column: usize, text: &mut CellText, palette: &Palette, ) -> CellStyle

Writes the text of the cell at row, column into text (empty on entry) and returns its style, in the grid’s colors (palette, which follows the theme).
Source§

fn prepare(&mut self)

Brings the model up to date before the grid paints (taking in data that arrived, for example). It may allocate when the data changed; it should not otherwise. It runs only when the grid paints, not while it is hidden (an inactive tab): feed a model that must keep up while hidden from the application, through DataGrid::model_mut.
Source§

fn showing(&mut self, rows: Range<usize>)

The rows the grid shows (every row it paints, the last perhaps cut off), each time it paints, after prepare. A model that fetches its rows, from a database or a query engine, asks for these and those around them; it should not allocate while it has them. Does nothing by default.
Source§

fn sort_state(&self) -> Option<(usize, SortOrder)>

The column and order the rows are sorted by now, if the model knows (a model sorted before the user clicked, or one that sorts itself); the grid shows it and reverses it on the next click.
Source§

fn columns_revision(&self) -> u64

Changes whenever columns changes (another schema, new widths): the grid then reads the columns again, keeping the widths the user dragged if the column titles are the same as before. Checked each frame after prepare.
Source§

fn row_key(&self, row: usize) -> Option<u64>

A value identifying the record at row while rows are added, removed or sorted (a database key, an instrument id). With it, a selection follows its record; without it (None, the default), a selection is a position and is cleared by sorting.
Source§

fn row_of_key(&self, key: u64) -> Option<usize>

Where the record row_key gave key for is now, if it is still shown. Asked once a frame while a row is selected: make it fast for large models. None (the record was removed, or is filtered out) clears the selection.
Source§

fn generation(&self) -> u64

Changes when the rows were replaced wholesale (another table), so that keys from before mean nothing: the grid then clears its selection and scrolls to the top. Checked each frame after prepare.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.