Struct jsonrpsee_http_server::RpcModule [−][src]
pub struct RpcModule<Context> { /* fields omitted */ }
Expand description
Sets of JSON-RPC methods can be organized into a “module“s that are in turn registered on the server or,
alternatively, merged with other modules to construct a cohesive API. RpcModule
wraps an additional context
argument that can be used to access data during call execution.
Implementations
Register a new synchronous RPC method, which computes the response with the given callback.
pub fn register_async_method<R, F>(
&mut self,
method_name: &'static str,
callback: F
) -> Result<(), Error> where
F: Fn(RpcParams<'_>, Arc<Context>) -> Pin<Box<dyn Future<Output = Result<R, CallError>> + 'static + Send, Global>> + Copy + Send + Sync + 'static,
R: Serialize + Send + Sync + 'static,
[src]
pub fn register_async_method<R, F>(
&mut self,
method_name: &'static str,
callback: F
) -> Result<(), Error> where
F: Fn(RpcParams<'_>, Arc<Context>) -> Pin<Box<dyn Future<Output = Result<R, CallError>> + 'static + Send, Global>> + Copy + Send + Sync + 'static,
R: Serialize + Send + Sync + 'static,
[src]Register a new asynchronous RPC method, which computes the response with the given callback.
Register a new RPC subscription that invokes callback on every subscription request. The callback itself takes three parameters: - RpcParams: JSONRPC parameters in the subscription request. - SubscriptionSink: A sink to send messages to the subscriber. - Context: Any type that can be embedded into the RpcContextModule.
Examples
use jsonrpsee_utils::server::rpc_module::RpcModule; let mut ctx = RpcModule::new(99_usize); ctx.register_subscription("sub", "unsub", |params, mut sink, ctx| { let x: usize = params.one()?; std::thread::spawn(move || { let sum = x + (*ctx); sink.send(&sum) }); Ok(()) });
Convert a module into methods. Consumes self.
Trait Implementations
Auto Trait Implementations
impl<Context> !RefUnwindSafe for RpcModule<Context>
impl<Context> !UnwindSafe for RpcModule<Context>