cuprate_rpc_interface/rpc_service.rs
1//! RPC [`tower::Service`] trait.
2
3//---------------------------------------------------------------------------------------------------- Use
4use std::future::Future;
5
6use tower::Service;
7
8//---------------------------------------------------------------------------------------------------- RpcService
9/// An RPC [`tower::Service`].
10///
11/// This trait solely exists to encapsulate the traits needed
12/// to handle RPC requests and respond with responses - **it is
13/// not meant to be used directly.**
14///
15/// The `Request` and `Response` are generic and
16/// are used in the [`tower::Service`] bounds.
17///
18/// The error type is always [`anyhow::Error`].
19///
20/// There is a blanket implementation that implements this
21/// trait on types that implement `tower::Service` correctly.
22///
23/// See [`RpcHandler`](crate::RpcHandler) for more information.
24pub trait RpcService<Request, Response>:
25 Clone
26 + Send
27 + Sync
28 + 'static
29 + Service<
30 Request,
31 Response = Response,
32 Error = anyhow::Error,
33 Future: Future<Output = Result<Response, anyhow::Error>> + Send + 'static,
34 >
35{
36}
37
38impl<Request, Response, T> RpcService<Request, Response> for T where
39 Self: Clone
40 + Send
41 + Sync
42 + 'static
43 + Service<
44 Request,
45 Response = Response,
46 Error = anyhow::Error,
47 Future: Future<Output = Result<Response, anyhow::Error>> + Send + 'static,
48 >
49{
50}