Skip to main content

HttpService

Trait HttpService 

Source
pub trait HttpService:
    Sealed
    + Clone
    + Send
    + Sync
    + 'static {
    type ResponseBody: Body<Data: Send, Error: Into<BoxError>> + Send + 'static;
    type Error: Into<BoxError>;
    type Future: Future<Output = Result<Response<Self::ResponseBody>, Self::Error>> + Send;

    // Required methods
    fn poll_ready(
        &mut self,
        cx: &mut Context<'_>,
    ) -> Poll<Result<(), Self::Error>>;
    fn call(&mut self, request: Request<Body>) -> Self::Future;
}
Expand description

What a transport has to be: a tower service that takes an http request with this crate’s Body and answers with an http response.

It is implemented for every tower_service::Service that fits, and for nothing else, so it is a name for a set of bounds rather than a trait to implement: implement Service and a type is a transport. The service is cloned for every request and driven with its own poll_ready, so a service with back-pressure keeps it; the default HyperTransport is always ready.

The error of the service, and of its response body, is anything that can cross threads. It is kept as the source of the connection Error the call fails with.

Required Associated Types§

Source

type ResponseBody: Body<Data: Send, Error: Into<BoxError>> + Send + 'static

The body of the responses the service answers with.

Source

type Error: Into<BoxError>

What the service fails with when it cannot produce a response.

Source

type Future: Future<Output = Result<Response<Self::ResponseBody>, Self::Error>> + Send

The future a call returns.

Required Methods§

Source

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Service::poll_ready, forwarded.

§Errors

Returns the service’s error when it can take no more requests.

Source

fn call(&mut self, request: Request<Body>) -> Self::Future

Service::call, forwarded.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<S, B> HttpService for S
where S: Service<Request<Body>, Response = Response<B>> + Clone + Send + Sync + 'static, S::Error: Into<BoxError>, S::Future: Send, B: Body<Data: Send, Error: Into<BoxError>> + Send + 'static,