1#![cfg_attr(not(feature = "std"), no_std)]
2
3extern crate alloc;
4
5mod impls;
6
7#[cfg(feature = "reactor")]
8mod reactor;
9
10use alloc::string::String;
11use alloc::vec::Vec;
12
13use serde::{Deserialize, Serialize};
14
15#[cfg(feature = "reactor")]
16pub use reactor::Reactor;
17
18#[cfg(feature = "reactor")]
19pub use tokio::{sync::mpsc, time};
20
21pub use serde_json::{json, Map, Value};
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24pub enum Error {
25 UnexpectedIdVariant,
26 UnexpectedParamsVariant,
27 UnexpectedRequestVariant,
28 InvalidNumberCast,
29 JsonRpcVersionNotFound,
30 InvalidJsonRpcVersion,
31 ExpectedId,
32 ExpectedMethod,
33 InvalidMethodVariant,
34 UnexpectedNotificationVariant,
35 UnexpectedErrorVariant,
36 ExpectedErrorCode,
37 ExpectedErrorCodeAsInteger,
38 ExpectedErrorMessage,
39 ExpectedErrorCodeAsString,
40 UnexpectedResponseVariant,
41 ResponseExpectsResultOrError,
42}
43
44#[derive(Debug, Clone, PartialEq, Eq, Hash)]
45pub enum Id {
46 String(String),
47 Number(i64),
48}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
51pub enum Params {
52 Array(Vec<Value>),
53 Object(Map<String, Value>),
54 Null,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct Request {
59 pub id: Id,
60 pub method: String,
61 pub params: Params,
62}
63
64#[derive(Debug, Clone, PartialEq, Eq)]
65pub struct Notification {
66 pub method: String,
67 pub params: Params,
68}
69
70#[derive(Debug, Clone, PartialEq, Eq)]
71pub struct RpcError {
72 pub code: i64,
73 pub message: String,
74 pub data: Value,
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct Response {
79 pub id: Id,
80 pub result: Result<Value, RpcError>,
81}