Trait HttpServiceFactory

Source
pub trait HttpServiceFactory {
    type Error;
    type Service: HttpService;

    // Required method
    fn new_service(
        &mut self,
        remote_addr: SocketAddr,
    ) -> impl Future<Output = Result<Self::Service, Self::Error>> + Send;
}
Expand description

A trait representing an HTTP service factory.

This trait must be implemented by types that can create new instances of HttpService. It is conceptually similar to tower’s MakeService trait.

It is intended to create a new service for each incoming connection. If you don’t need to implement any custom factory logic, you can use ServiceCloneFactory to make a factory that clones the given service for each new connection.

Required Associated Types§

Source

type Error

The error type that can be returned by new_service.

Source

type Service: HttpService

The service type that is created by this factory.

Required Methods§

Source

fn new_service( &mut self, remote_addr: SocketAddr, ) -> impl Future<Output = Result<Self::Service, Self::Error>> + Send

Create a new service for a new connection.

remote_addr is the address of the connecting remote peer.

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§

Source§

impl<F, Fut, E, S> HttpServiceFactory for FnHttpServiceFactory<F>
where F: Fn(SocketAddr) -> Fut, Fut: Future<Output = Result<S, E>> + Send, E: Error, S: HttpService,

Source§

impl<M> HttpServiceFactory for TowerMakeServiceWithAddrFactory<M>
where M: MakeService<SocketAddr, IncomingRequest> + Send, M::Future: Send, M::Service: HttpService,

Available on crate feature tower only.
Source§

type Error = <M as MakeService<SocketAddr, Request<IncomingBody>>>::MakeError

Source§

type Service = <M as MakeService<SocketAddr, Request<IncomingBody>>>::Service

Source§

impl<M, T> HttpServiceFactory for TowerMakeServiceFactory<M, T>
where M: MakeService<T, IncomingRequest> + Send, M::Future: Send, M::Service: HttpService, T: Clone + Send,

Available on crate feature tower only.
Source§

type Error = <M as MakeService<T, Request<IncomingBody>>>::MakeError

Source§

type Service = <M as MakeService<T, Request<IncomingBody>>>::Service

Source§

impl<S> HttpServiceFactory for ServiceCloneFactory<S>
where S: HttpService + Clone + Send,