Trait Client

pub trait Client<Error, InputStreamError = Error, OutputStreamError = Error> {
    type Request: ClientReq<Error> + Send + 'static;
    type Response: ClientRes<Error> + Send + 'static;

    // Required methods
    fn send(
        req: Self::Request,
    ) -> impl Future<Output = Result<Self::Response, Error>> + Send;
    fn open_websocket(
        path: &str,
    ) -> impl Future<Output = Result<(impl Stream<Item = Result<Bytes, Bytes>> + Send + 'static, impl Sink<Bytes> + Send + 'static), Error>> + Send;
    fn spawn(future: impl Future<Output = ()> + Send + 'static);
}
Expand description

A client defines a pair of request/response types and the logic to send and receive them.

This trait is implemented for things like a browser fetch request or for the reqwest trait. It should almost never be necessary to implement it yourself, unless you’re trying to use an alternative HTTP crate on the client side.

Required Associated Types§

type Request: ClientReq<Error> + Send + 'static

The type of a request sent by this client.

type Response: ClientRes<Error> + Send + 'static

The type of a response received by this client.

Required Methods§

fn send( req: Self::Request, ) -> impl Future<Output = Result<Self::Response, Error>> + Send

Sends the request and receives a response.

fn open_websocket( path: &str, ) -> impl Future<Output = Result<(impl Stream<Item = Result<Bytes, Bytes>> + Send + 'static, impl Sink<Bytes> + Send + 'static), Error>> + Send

Opens a websocket connection to the server.

fn spawn(future: impl Future<Output = ()> + Send + 'static)

Spawn a future that runs in the background.

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§

§

impl<Error, InputStreamError, OutputStreamError> Client<Error, InputStreamError, OutputStreamError> for BrowserClient
where Error: FromServerFnError, InputStreamError: FromServerFnError, OutputStreamError: FromServerFnError,