pub trait Backend {
    fn init<'async_trait>(
        events: Sender<Event>,
        requests: Sender<ReactorReverseRequest>
    ) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
    where
        Self: 'async_trait
; fn request<'life0, 'async_trait>(
        &'life0 mut self,
        request: Request
    ) -> Pin<Box<dyn Future<Output = Option<Response>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; fn response<'life0, 'async_trait>(
        &'life0 mut self,
        id: u64,
        response: Response
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; }

Required Methods

Initialize a new instance of a backend.

The provided mpsc senders will be listened by the reactor and forwarded to the client

If an id is provided via Option<u64>, it will be the id of the response. Otherwise, the reactor will pick the next available id.

A request was sent by the client. It should be replied as response.

This is infallible because any error that might have happened should be described as a valid response with success set to false.

Ideally, a backend will always produce a response out of a request. However, this is an implementation decision so we require Option instead. If None is passed, the reactor will not submit a response to the incoming request - this need to be used carefully because the client might end up in a dangling state for the protocol asks to always provide a response.

The client replied to a reverse request

Implementors