pub trait Chainer {
type State: Sync + Send + Default;
// Required method
fn chain<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
result: Result<Response, Error>,
state: &'life1 mut Self::State,
request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Result<Option<Response>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided method
fn max_chain_length(&self) -> u32 { ... }
}
Expand description
Describes:
- which request outcomes should be retried
- how the request should be updated to retry
Required Associated Types§
Required Methods§
Sourcefn chain<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
result: Result<Response, Error>,
state: &'life1 mut Self::State,
request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Result<Option<Response>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn chain<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
result: Result<Response, Error>,
state: &'life1 mut Self::State,
request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Result<Option<Response>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Inspect the result of the previous request, to decide whether to make another request.
- If another request is required, update the previous request to form the
next request in the chain, and return
Ok(None)
. - If the response is ready, return it inside
Ok(Some(response))
. - If an error occurs and you cannot continue, return
Err(error)
.
Returning a response, or an error, will result in termination of the chain.
Information is available from:
- self (global state, instantiated at middleware creation)
- result (the result of the previous request)
- state (local state, instantiated for each request chain)
Global side effects can be managed via interior mutability of self
.
Provided Methods§
Sourcefn max_chain_length(&self) -> u32
fn max_chain_length(&self) -> u32
Safety valve to protect against infinite chaining.
This value may be overriden by the user.