Struct jsonrpsee_ws_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

Create a new module with a given shared Context.

Register a new synchronous RPC method, which computes the response with the given callback.

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: - Params: JSONRPC parameters in the subscription request. - SubscriptionSink: A sink to send messages to the subscriber. - Context: Any type that can be embedded into the RpcModule.

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(())
});

Register an alias for an existing_method. Alias uniqueness is enforced.

Methods from Deref<Target = Methods>

Merge two Methods’s by adding all MethodCallbacks from other into self. Fails if any of the methods in other is present already.

Returns the method callback.

Attempt to execute a callback, sending the resulting JSON (success or error) to the specified sink.

Attempt to execute a callback while checking that the call does not exhaust the available resources, sending the resulting JSON (success or error) to the specified sink.

Helper to call a method on the RPC module without having to spin up a server.

The params must be serializable as JSON array, see ToRpcParams for further documentation.

Helper alternative to execute, useful for writing unit tests without having to spin a server up.

Test helper that sets up a subscription using the given method. Returns a tuple of the SubscriptionId and a channel on which subscription JSON payloads can be received.

Returns an Iterator with all the method names registered on this server.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.