mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-09 20:40:01 +00:00
92800810d9
* readme * cuprated: add all workspace deps * cuprated: add lints * !! * add state, fn signatures * fixes * error signatures * interface: handle json-rpc concepts * split rpc calls into 3 `Service`s * interface: extract out to `RpcService` * fix merge * remove crate lints * use `BoxFuture` * rpc/interface: impl `thiserror::Error` * split state from main handler struct * cleanup * fix imports * replace `RpcError` with `anyhow::Error` * interface: update error * cuprated: update error type
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
//! RPC [`tower::Service`] trait.
|
|
|
|
//---------------------------------------------------------------------------------------------------- Use
|
|
use std::future::Future;
|
|
|
|
use tower::Service;
|
|
|
|
//---------------------------------------------------------------------------------------------------- RpcService
|
|
/// An RPC [`tower::Service`].
|
|
///
|
|
/// This trait solely exists to encapsulate the traits needed
|
|
/// to handle RPC requests and respond with responses - **it is
|
|
/// not meant to be used directly.**
|
|
///
|
|
/// The `Request` and `Response` are generic and
|
|
/// are used in the [`tower::Service`] bounds.
|
|
///
|
|
/// The error type is always [`anyhow::Error`].
|
|
///
|
|
/// There is a blanket implementation that implements this
|
|
/// trait on types that implement `tower::Service` correctly.
|
|
///
|
|
/// See [`RpcHandler`](crate::RpcHandler) for more information.
|
|
pub trait RpcService<Request, Response>:
|
|
Clone
|
|
+ Send
|
|
+ Sync
|
|
+ 'static
|
|
+ Service<
|
|
Request,
|
|
Response = Response,
|
|
Error = anyhow::Error,
|
|
Future: Future<Output = Result<Response, anyhow::Error>> + Send + 'static,
|
|
>
|
|
{
|
|
}
|
|
|
|
impl<Request, Response, T> RpcService<Request, Response> for T where
|
|
Self: Clone
|
|
+ Send
|
|
+ Sync
|
|
+ 'static
|
|
+ Service<
|
|
Request,
|
|
Response = Response,
|
|
Error = anyhow::Error,
|
|
Future: Future<Output = Result<Response, anyhow::Error>> + Send + 'static,
|
|
>
|
|
{
|
|
}
|