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