pub trait Callbacks<FailureClass>: Sized {
type Data;
// Required method
fn prepare<B>(&mut self, request: &Request<B>) -> Self::Data;
// Provided methods
fn on_response<B>(
&mut self,
_response: &Response<B>,
_classification: ClassifiedResponse<FailureClass, ()>,
_data: &mut Self::Data,
) { ... }
fn on_eos(
self,
_trailers: Option<&HeaderMap>,
_classification: Result<(), FailureClass>,
_data: Self::Data,
) { ... }
fn on_failure(
self,
_failed_at: FailedAt,
_failure_classification: FailureClass,
_data: &mut Self::Data,
) { ... }
}Expand description
Trait that defines callbacks for LifeCycle to call.
Required Associated Types§
Required Methods§
Sourcefn prepare<B>(&mut self, request: &Request<B>) -> Self::Data
fn prepare<B>(&mut self, request: &Request<B>) -> Self::Data
Create an instance of Self::Data from the request.
This method is called immediately after the request is received by Service::call.
The value returned here will be passed to the other methods in this trait.
Provided Methods§
Sourcefn on_response<B>(
&mut self,
_response: &Response<B>,
_classification: ClassifiedResponse<FailureClass, ()>,
_data: &mut Self::Data,
)
fn on_response<B>( &mut self, _response: &Response<B>, _classification: ClassifiedResponse<FailureClass, ()>, _data: &mut Self::Data, )
Perform some action when a response has been generated.
This method is called when the inner Service’s response future
completes with Ok(response), regardless if the response is classified
as a success or a failure.
If the response is the start of a stream (as determined by the
classifier passed to LifeCycle::new or LifeCycleLayer::new) then
classification will be ClassifiedResponse::RequiresEos(()),
otherwise it will be ClassifiedResponse::Ready.
The default implementation does nothing and returns immediately.
Sourcefn on_eos(
self,
_trailers: Option<&HeaderMap>,
_classification: Result<(), FailureClass>,
_data: Self::Data,
)
fn on_eos( self, _trailers: Option<&HeaderMap>, _classification: Result<(), FailureClass>, _data: Self::Data, )
Perform some action when a stream has ended.
This is called when Body::poll_frame produces Ok(trailers) with the Frame::into_trailers method,
regardless if the trailers are classified as a failure.
A stream that ends successfully will trigger two callbacks.
on_response will be called once the response has been generated and
the stream has started and on_eos will be called once the stream has
ended.
If the trailers were classified as a success then classification will
be Ok(()) otherwise Err(failure_class).
The default implementation does nothing and returns immediately.
Sourcefn on_failure(
self,
_failed_at: FailedAt,
_failure_classification: FailureClass,
_data: &mut Self::Data,
)
fn on_failure( self, _failed_at: FailedAt, _failure_classification: FailureClass, _data: &mut Self::Data, )
Perform some action when an error has been encountered.
This method is only called in the following scenarios:
- The inner
Service’s response future resolves to an error. Body::poll_framereturns an error.
That means this method is not called if a response is classified as a
failure (then on_response is called) or an end-of-stream is
classified as a failure (then on_eos is called).
failed_at specifies where the error happened.
The default implementation does nothing and returns immediately.
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.