ExactLoader

Trait ExactLoader 

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

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

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

Trait for loading items on-demand from an data source that let’s you request precise ranges.

Implement this if your data source actually returns exactly the range of items requested and if it can provide the total number of items.

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_items( &self, range: Range<usize>, query: &Self::Query, ) -> impl Future<Output = Result<Vec<Self::Item>, Self::Error>>

Does the actual loading of items.

This will be called with a range respecting the chunk size. The query data can be used to filter or sort the items for example.

It returns a list of items. If the number of items is less than the requested range, it means that the end of the data source has been reached.

Provided Methods§

Source

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

The total number of items of this data source with respect to the 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§