Trait BatchFunction

Source
pub trait BatchFunction<K, V> {
    type Context;

    // Required method
    fn load<'life0, 'life1, 'async_trait>(
        keys: &'life0 [K],
        context: &'life1 Self::Context,
    ) -> Pin<Box<dyn Future<Output = Vec<(K, V)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A BatchFunction defines the method through which some Loader may fetch batched data from some resource. The BatchFunction receives a slice of keys that have been requested during the Loader’s most recent execution frame, and some user defined context struct.

Unlike the reference facebook dataloader implementation, the BatchFunction is not required to return a result for all keys that were provided. Instead, it can return any set of loaded key value pairs, in any order it chooses. Requesters of keys whose values are not returned by the BatchFunction will receive a None. Error handling and reporting is expected to be done within the BatchFunction (i.e. through some error sink in the context).

Multiple BatchFunctions (and therefore loaders) can share the same context (likely through an Arc).

Required Associated Types§

Required Methods§

Source

fn load<'life0, 'life1, 'async_trait>( keys: &'life0 [K], context: &'life1 Self::Context, ) -> Pin<Box<dyn Future<Output = Vec<(K, V)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

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§