PaginatedLoader

Trait PaginatedLoader 

Source
pub trait PaginatedLoader {
    type Item;
    type Query;
    type Error: Debug + 'static;

    const PAGE_ITEM_COUNT: usize;

    // Required method
    fn load_page(
        &self,
        page_index: usize,
        query: &Self::Query,
    ) -> impl Future<Output = Result<Vec<Self::Item>, Self::Error>>;

    // Provided method
    fn count(
        &self,
        _query: &Self::Query,
    ) -> impl Future<Output = Result<Option<PaginatedCount>, Self::Error>> { ... }
}
Expand description

Loader trait for loading items on-demand from a paginated data source.

Please note that this is independent of if you use pagination or virtualization in your UI. This just referrs to the data source. So if you have an API for example, that returns the data paginated, then this is for you.

Required Associated Constants§

Source

const PAGE_ITEM_COUNT: usize

How many rows per page

Required Associated Types§

Source

type Item

The type of items that will be loaded.

Source

type Query

The type of the query data that will be used to load items.

Can be used to filter or sort the items for example.

Source

type Error: Debug + 'static

The type of errors that can occur during loading.

Required Methods§

Source

fn load_page( &self, page_index: usize, query: &Self::Query, ) -> impl Future<Output = Result<Vec<Self::Item>, Self::Error>>

Get all data items specified by the page index (starts a 0) and the query.

If you return less than PAGE_ITEM_COUNT rows, it is assumed that the end of the data has been reached.

Provided Methods§

Source

fn count( &self, _query: &Self::Query, ) -> impl Future<Output = Result<Option<PaginatedCount>, Self::Error>>

The total number of items of this data source with respect to the given query.

Returns Ok(None) if unknown (which is the default).

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§