rpc_router/
lib.rs

1//! rpc::router module provides the type and implementation for
2//! json rpc routing.
3//!
4//! It has the following constructs:
5//!
6//! - `RpcRouter` holds the HashMap of `method_name: Box<dyn RpcHandlerWrapperTrait>`.
7//! - `RpcHandler` trait is implemented for any async function that, with
8//!   `(S1, S2, ...[impl IntoParams])`, returns `web::Result<Serialize>` where S1, S2, ... are
9//!    types that implement `FromResources` (see router/from_resources.rs and src/resources.rs).
10//! - `IntoParams` is the trait to implement to instruct how to go from `Option<Value>` json-rpc params
11//!   to the handler's param types.
12//! - `IntoParams` has a default `into_params` implementation that will return an error if the params are missing.
13//!
14//! ```
15//! #[derive(Deserialize)]
16//! pub struct ParamsIded {
17//!   id: i64,
18//! }
19//!
20//! impl IntoParams for ParamsIded {}
21//! ```
22//!
23//! - For custom `IntoParams` behavior, implement the `IntoParams::into_params` function.
24//! - Implementing `IntoDefaultParams` on a type that implements `Default` will auto-implement `IntoParams`
25//!   and call `T::default()` when the params `Option<Value>` is None.
26//!
27
28// region:    --- Modules
29
30mod error;
31mod handler;
32mod params;
33mod request;
34mod resource;
35mod router;
36
37// -- Flatten
38pub use self::error::{Error, Result};
39pub use handler::{Handler, HandlerError, HandlerResult, IntoHandlerError};
40pub use params::*;
41pub use request::*;
42pub use resource::*;
43pub use router::*;
44
45// -- Export proc macros
46pub use rpc_router_macros::RpcHandlerError;
47pub use rpc_router_macros::RpcParams;
48pub use rpc_router_macros::RpcResource;
49
50// endregion: --- Modules