jsonrpsee_core/
lib.rs

1// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2//
3// Permission is hereby granted, free of charge, to any
4// person obtaining a copy of this software and associated
5// documentation files (the "Software"), to deal in the
6// Software without restriction, including without
7// limitation the rights to use, copy, modify, merge,
8// publish, distribute, sublicense, and/or sell copies of
9// the Software, and to permit persons to whom the Software
10// is furnished to do so, subject to the following
11// conditions:
12//
13// The above copyright notice and this permission notice
14// shall be included in all copies or substantial portions
15// of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27//! Shared utilities for `jsonrpsee`.
28
29#![cfg_attr(not(test), warn(unused_crate_dependencies))]
30#![cfg_attr(docsrs, feature(doc_cfg))]
31
32// Macros useful internally within this crate, but not to be exposed outside of it.
33#[macro_use]
34mod macros;
35
36/// Error type.
37pub mod error;
38
39/// Traits
40pub mod traits;
41
42/// RPC Parameters.
43pub mod params;
44
45cfg_http_helpers! {
46	pub mod http_helpers;
47}
48
49cfg_server! {
50	pub mod id_providers;
51	pub mod server;
52}
53
54cfg_client! {
55	pub mod client;
56	pub use client::Error as ClientError;
57}
58
59cfg_client_or_server! {
60	pub mod middleware;
61}
62
63pub use async_trait::async_trait;
64pub use error::{RegisterMethodError, SubscriptionError};
65
66/// JSON-RPC result.
67pub type RpcResult<T> = std::result::Result<T, jsonrpsee_types::ErrorObjectOwned>;
68
69/// Empty server `RpcParams` type to use while registering modules.
70pub type EmptyServerParams = Vec<()>;
71
72#[doc(hidden)]
73mod proc_macros_support;
74
75/// Re-exports for proc-macro library to not require any additional
76/// dependencies to be explicitly added on the client side.
77#[doc(hidden)]
78pub mod __reexports {
79	pub use async_trait::async_trait;
80	pub use serde;
81	pub use serde_json;
82
83	// Needed for the params parsing in the proc macro API.
84	cfg_client_or_server! {
85		pub use tokio;
86	}
87
88	pub use super::proc_macros_support::*;
89}
90
91pub use serde::{Serialize, de::DeserializeOwned};
92pub use serde_json::{
93	Value as JsonValue, to_value as to_json_value, value::RawValue as JsonRawValue,
94	value::to_raw_value as to_json_raw_value,
95};
96pub use std::borrow::Cow;
97
98/// Ten megabytes.
99pub const TEN_MB_SIZE_BYTES: u32 = 10 * 1024 * 1024;
100
101/// The return type if the subscription wants to return `Result`.
102pub type SubscriptionResult = Result<(), SubscriptionError>;
103
104/// Type erased error.
105pub type BoxError = Box<dyn std::error::Error + Send + Sync>;