Client

Trait Client 

Source
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§

Source

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

The type of a request sent by this client.

Source

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

The type of a response received by this client.

Required Methods§

Source

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

Sends the request and receives a response.

Source

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.

Source

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§

Source§

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

Source§

impl<Error: FromServerFnError, InputStreamError: FromServerFnError, OutputStreamError: FromServerFnError> Client<Error, InputStreamError, OutputStreamError> for ReqwestClient