Loader

Trait Loader 

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

    const CHUNK_SIZE: Option<usize> = None;

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

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

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

This is the most generic loader trait. Please have a look first at the other loader traits as they usually are simpler to implement. Only if they are not sufficient, you should implement this trait.

Provided Associated Constants§

Source

const CHUNK_SIZE: Option<usize> = None

If this Some(…) then the data will be loaded in chunks of this size. This is useful for paginated data sources. Please look at [PaginatedLoader] if you have such a paginated data source.

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<LoadedItems<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 LoadedItems containing the loaded items as well with the loaded range which can be different from the requested range if the data source can’t provide the exact requested range.

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§