jsonrpc_rs/
channel.rs

1use futures::{Sink, Stream};
2use std::future::Future;
3
4use crate::RPCResult;
5
6/// Transport input item
7pub type TransportInput<E> = Result<RPCData, E>;
8
9/// Transport output item.
10pub type RPCData = bytes::Bytes;
11
12/// Define abstract transport channel for [`crate::Client`] and [`crate::Server`]
13pub trait TransportChannel: 'static {
14    /// Transport channel error type.
15    type SinkError: std::error::Error + 'static + Sync + Send;
16
17    type StreamError: std::error::Error + 'static + Sync + Send;
18
19    /// Input stream must support [`Send`] + [`Sync`]
20    type Input: Stream<Item = TransportInput<Self::StreamError>> + Unpin + Send + 'static;
21
22    type Output: Sink<RPCData, Error = Self::SinkError> + Unpin + Send + 'static;
23
24    fn spawn<Fut>(future: Fut)
25    where
26        Fut: Future<Output = RPCResult<()>> + Send + 'static;
27
28    fn framed(self) -> (Self::Input, Self::Output);
29}