async_json_rpc/clients/
mod.rs1pub mod http;
2
3use std::{error, fmt};
4
5pub trait RequestFactory {
6 fn build_request(&self) -> crate::objects::RequestBuilder;
7}
8
9#[derive(Debug)]
11pub enum Error<E> {
12 BatchDuplicateResponseId(serde_json::Value),
14 Connection(E),
16 EmptyBatch,
18 Json(serde_json::Error),
20 NonceMismatch,
22 VersionMismatch,
24 WrongBatchResponseId(serde_json::Value),
26 WrongBatchResponseSize,
28}
29
30impl<E: fmt::Display> fmt::Display for Error<E> {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 let printable = match self {
33 Error::BatchDuplicateResponseId(err) => {
34 return write!(f, "duplicate batch response id, {}", err)
35 }
36 Error::Connection(err) => return err.fmt(f),
37 Error::EmptyBatch => "empty batch",
38 Error::Json(err) => return err.fmt(f),
39 Error::NonceMismatch => "nonce mismatch",
40 Error::VersionMismatch => "version mismatch",
41 Error::WrongBatchResponseId(err) => {
42 return write!(f, "wrong batch response id, {}", err)
43 }
44 Error::WrongBatchResponseSize => "wrong batch response size",
45 };
46 write!(f, "{}", printable)
47 }
48}
49
50impl<E: fmt::Display + fmt::Debug> error::Error for Error<E> {}