1#![cfg_attr(feature = "docs", feature(doc_cfg, external_doc))]
2#![cfg_attr(feature = "docs", doc(include = "../README.md"))]
3#![cfg_attr(feature = "docs", warn(missing_docs))]
4
5use bytes::Bytes;
6use roa::preload::*;
7use roa::{async_trait, Context, Endpoint, Result, State};
8
9#[doc(no_inline)]
10pub use jsonrpc_v2::*;
11
12pub struct RpcEndpoint<R>(pub Server<R>);
17
18#[async_trait(? Send)]
19impl<'a, S, R> Endpoint<'a, S> for RpcEndpoint<R>
20where
21 S: State,
22 R: Router + Sync + Send + 'static,
23{
24 #[inline]
25 async fn call(&'a self, ctx: &'a mut Context<S>) -> Result {
26 let data = ctx.read().await?;
27 let resp = self.0.handle(Bytes::from(data)).await;
28 ctx.write_json(&resp)
29 }
30}