async_jsonrpc_client/
transport.rs1use std::error::Error;
2
3use futures::stream::Stream;
4use jsonrpc_types::*;
5
6#[async_trait::async_trait]
8pub trait Transport {
9 type Error: Error;
11
12 async fn request<M>(&self, method: M, params: Option<Params>) -> Result<Output, Self::Error>
14 where
15 M: Into<String> + Send;
16}
17
18#[async_trait::async_trait]
20pub trait BatchTransport: Transport {
21 async fn request_batch<I, M>(&self, batch: I) -> Result<Vec<Output>, Self::Error>
23 where
24 I: IntoIterator<Item = (M, Option<Params>)> + Send,
25 I::IntoIter: Send,
26 M: Into<String>;
27}
28
29#[async_trait::async_trait]
31pub trait PubsubTransport: Transport {
32 type NotificationStream: Stream<Item = SubscriptionNotification>;
34
35 async fn subscribe<M>(
39 &self,
40 subscribe_method: M,
41 params: Option<Params>,
42 ) -> Result<(Id, Self::NotificationStream), Self::Error>
43 where
44 M: Into<String> + Send;
45
46 async fn unsubscribe<M>(&self, unsubscribe_method: M, subscription_id: Id) -> Result<bool, Self::Error>
48 where
49 M: Into<String> + Send;
50}