Skip to main content

DataLoader

Trait DataLoader 

Source
pub trait DataLoader<S> {
    type Args: FromRequestParts<S>;
    type Data: Serialize + Send;
    type Error: Error + Send;

    // Required method
    fn load_data(
        &self,
        params: Self::Args,
    ) -> impl Future<Output = Result<Self::Data, Self::Error>> + Send;

    // Provided method
    fn render_error(
        &self,
        error: Self::Error,
    ) -> impl Future<Output = impl IntoResponse + Send> + Send { ... }
}
Expand description

Give a generic piece of data based on the request parameters. This data might be used together with different handlers like the crate::FormHandler or the crate::JsonHandler to render either HTML or JSON data. In case it is paired with such a handler and some error happens in this handler, you will have a axum::extract::Extension<crate::HandlerError> in your Self::Args so you can handle the error case

Required Associated Types§

Required Methods§

Source

fn load_data( &self, params: Self::Args, ) -> impl Future<Output = Result<Self::Data, Self::Error>> + Send

Provide the data that is required to render a certain template

Provided Methods§

Source

fn render_error( &self, error: Self::Error, ) -> impl Future<Output = impl IntoResponse + Send> + Send

Map an emitted error to a response, this can be used to render another error template instead of the plain error text

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§