pub struct Server<C> { /* private fields */ }Expand description
A JSON-RPC 2.0 server.
Generic over a context type C that is cloned once per handler invocation.
§Example
use jsonrpc::{Server, Error};
let mut server = Server::new();
server.register("add", |_: (), (a, b): (i64, i64)| async move {
Ok::<_, Error>(a + b)
});Implementations§
Source§impl<C: Send + Sync + 'static> Server<C>
impl<C: Send + Sync + 'static> Server<C>
Sourcepub fn register<P, R, E, F>(
&mut self,
method: impl Into<String>,
handler: impl Fn(C, P) -> F + Send + Sync + 'static,
)
pub fn register<P, R, E, F>( &mut self, method: impl Into<String>, handler: impl Fn(C, P) -> F + Send + Sync + 'static, )
Registers an async handler for the given method name.
The handler receives an owned clone of the context and deserialized method parameters, and returns a future.
Sourcepub async fn handle(&self, ctx: C, message: RequestMessage) -> ResponseMessagewhere
C: Clone,
pub async fn handle(&self, ctx: C, message: RequestMessage) -> ResponseMessagewhere
C: Clone,
Handles a request message and returns the corresponding response message.
The context ctx is consumed and, for batches, cloned once per handler invocation.
Auto Trait Implementations§
impl<C> !RefUnwindSafe for Server<C>
impl<C> !UnwindSafe for Server<C>
impl<C> Freeze for Server<C>
impl<C> Send for Server<C>
impl<C> Sync for Server<C>
impl<C> Unpin for Server<C>
impl<C> UnsafeUnpin for Server<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more