Trait Protocol

Source
pub trait Protocol<Input, Output, Client, Server, Error, InputStreamError = Error, OutputStreamError = Error>
where Server: Server<Error, InputStreamError, OutputStreamError>, Client: Client<Error, InputStreamError, OutputStreamError>,
{ const METHOD: Method; // Required methods fn run_server<F, Fut>( request: <Server as Server<Error, InputStreamError, OutputStreamError>>::Request, server_fn: F, ) -> impl Future<Output = Result<<Server as Server<Error, InputStreamError, OutputStreamError>>::Response, Error>> + Send where F: Fn(Input) -> Fut + Send, Fut: Future<Output = Result<Output, Error>> + Send; fn run_client( path: &str, input: Input, ) -> impl Future<Output = Result<Output, Error>> + Send; }
Expand description

The protocol that a server function uses to communicate with the client. This trait handles the server and client side of running a server function. It is implemented for the Http and Websocket protocols and can be used to implement custom protocols.

Required Associated Constants§

Source

const METHOD: Method

The HTTP method used for requests.

Required Methods§

Source

fn run_server<F, Fut>( request: <Server as Server<Error, InputStreamError, OutputStreamError>>::Request, server_fn: F, ) -> impl Future<Output = Result<<Server as Server<Error, InputStreamError, OutputStreamError>>::Response, Error>> + Send
where F: Fn(Input) -> Fut + Send, Fut: Future<Output = Result<Output, Error>> + Send,

Run the server function on the server. The implementation should handle deserializing the input, running the server function, and serializing the output.

Source

fn run_client( path: &str, input: Input, ) -> impl Future<Output = Result<Output, Error>> + Send

Run the server function on the client. The implementation should handle serializing the input, sending the request, and deserializing the output.

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<Input, InputItem, OutputItem, InputEncoding, OutputEncoding, Client, Server, Error, InputStreamError, OutputStreamError> Protocol<Input, BoxedStream<OutputItem, OutputStreamError>, Client, Server, Error, InputStreamError, OutputStreamError> for Websocket<InputEncoding, OutputEncoding>
where Input: Deref<Target = BoxedStream<InputItem, InputStreamError>> + Into<BoxedStream<InputItem, InputStreamError>> + From<BoxedStream<InputItem, InputStreamError>>, InputEncoding: Encodes<InputItem> + Decodes<InputItem>, OutputEncoding: Encodes<OutputItem> + Decodes<OutputItem>, InputStreamError: FromServerFnError + Send, OutputStreamError: FromServerFnError + Send, Error: FromServerFnError + Send, Server: Server<Error, InputStreamError, OutputStreamError>, Client: Client<Error, InputStreamError, OutputStreamError>, OutputItem: Send + 'static, InputItem: Send + 'static,

Source§

const METHOD: Method = Method::GET

Source§

impl<InputProtocol, OutputProtocol, Input, Output, Client, Server, E> Protocol<Input, Output, Client, Server, E> for Http<InputProtocol, OutputProtocol>
where Input: IntoReq<InputProtocol, <Client as Client<E>>::Request, E> + FromReq<InputProtocol, <Server as Server<E>>::Request, E> + Send, Output: IntoRes<OutputProtocol, <Server as Server<E>>::Response, E> + FromRes<OutputProtocol, <Client as Client<E>>::Response, E> + Send, E: FromServerFnError, InputProtocol: Encoding, OutputProtocol: Encoding, Client: Client<E>, Server: Server<E>,

Source§

const METHOD: Method = InputProtocol::METHOD