Trait Svc

Source
pub trait Svc<Req> {
    type Res;
    type Fut: Future<Output = Self::Res>;

    // Required method
    fn exec(self: Pin<&mut Self>, req: Req) -> Self::Fut;

    // Provided method
    fn poll_ready(self: Pin<&mut Self>, cx: Context<'_>) -> Poll<()> { ... }
}
Expand description

Service trait representing an asynchronous request/response operation.

Required Associated Types§

Source

type Res

Output type.

Source

type Fut: Future<Output = Self::Res>

Response future.

Required Methods§

Source

fn exec(self: Pin<&mut Self>, req: Req) -> Self::Fut

Processes request, producing a future that outputs the response type.

Provided Methods§

Source

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

To be called before exec to signal wether the service is ready to process requests. As such, the check should be inexpensive. Returning Poll::Pending acts as back-pressure. The default implementation unconditionally indicates the service is ready.

Implementations on Foreign Types§

Source§

impl<S, Req> Svc<Req> for Box<S>
where S: Svc<Req>,

Source§

type Res = <S as Svc<Req>>::Res

Source§

type Fut = <S as Svc<Req>>::Fut

Source§

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

Source§

fn exec(self: Pin<&mut Self>, req: Req) -> Self::Fut

Implementors§

Source§

impl<F, Req, Fut, Res> Svc<Req> for FnSvc<F>
where F: FnMut(Req) -> Fut + Unpin, Fut: Future<Output = Res>,

Source§

type Res = Res

Source§

type Fut = Fut

Source§

impl<Req, Res> Svc<Req> for BoxSvc<Req, Res>

Source§

type Res = Res

Source§

type Fut = Pin<Box<dyn Future<Output = Res>>>

Source§

impl<S1, S2, Req, Int, Res> Svc<Req> for ThenSvc<S1, S2, Int, Res>
where S1: Svc<Req, Res = Int>, S2: Svc<Int, Res = Res>,

Source§

type Res = Res

Source§

type Fut = ThenSvcFut<S1, S2, Req, Int, Res>

Source§

impl<S, Req, F, Res> Svc<Req> for MapSvc<S, F, Res>
where S: Svc<Req>, F: FnMut(S::Res) -> Res + Clone,

Source§

type Res = Res

Source§

type Fut = MapSvcFut<S, F, Req, Res>