Skip to main content

Upstream

Trait Upstream 

Source
pub trait Upstream<Req> {
    type Response;
    type Future: Future<Output = Self::Response> + Send;

    // Required method
    fn call(&mut self, req: Req) -> Self::Future;
}
Expand description

Trait for calling upstream services with cacheable requests.

This trait is framework-agnostic and can be implemented for any async service.

§Examples

use hitbox_core::Upstream;
use std::future::Ready;

struct MockUpstream {
    response: MyResponse,
}

impl Upstream<MyRequest> for MockUpstream {
    type Response = MyResponse;
    type Future = Ready<Self::Response>;

    fn call(&mut self, _req: MyRequest) -> Self::Future {
        std::future::ready(self.response.clone())
    }
}

Required Associated Types§

Source

type Response

The response type returned by the upstream service

Source

type Future: Future<Output = Self::Response> + Send

The future that resolves to the response

Required Methods§

Source

fn call(&mut self, req: Req) -> Self::Future

Call the upstream service with the given request

Implementors§