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§
Sourceconst CHUNK_SIZE: Option<usize> = None
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§
Required Methods§
Sourcefn load_items(
&self,
range: Range<usize>,
query: &Self::Query,
) -> impl Future<Output = Result<LoadedItems<Self::Item>, Self::Error>>
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§
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.