Trait Handler

Source
pub trait Handler {
    type Metadata: PubSubMetadata + Unpin + Debug;

    // Required methods
    fn add_method<F>(&mut self, name: &str, method: F)
       where F: RpcMethodSimple;
    fn add_subscription<F, G>(
        &mut self,
        notification: &str,
        subscribe: (&str, F),
        unsubscribe: (&str, G),
    )
       where F: SubscribeRpcMethod<Self::Metadata>,
             G: UnsubscribeRpcMethod<Self::Metadata>;
    fn as_meta_io_handler(&self) -> MetaIoHandler<Self::Metadata>;
    fn describe_api(&self) -> Vec<String>;
    fn handle_request_sync(
        &self,
        request: &str,
        meta: Self::Metadata,
    ) -> Option<String>;
    fn metadata_from_sender(sender: UnboundedSender<String>) -> Self::Metadata;
    fn new() -> Self;
}
Expand description

Trait that abstracts away different implementations of IO handlers.

Required Associated Types§

Source

type Metadata: PubSubMetadata + Unpin + Debug

The type to use as the metadata for the IO handler. Especially relevant for PubSub.

Required Methods§

Source

fn add_method<F>(&mut self, name: &str, method: F)
where F: RpcMethodSimple,

Add a JSON-RPC method.

Source

fn add_subscription<F, G>( &mut self, notification: &str, subscribe: (&str, F), unsubscribe: (&str, G), )

Add a JSON-RPC subscription.

Source

fn as_meta_io_handler(&self) -> MetaIoHandler<Self::Metadata>

Cast this down to an instance of MetaIoHandler.

Source

fn describe_api(&self) -> Vec<String>

Get a list of all the supported JSON-RPC methods.

Source

fn handle_request_sync( &self, request: &str, meta: Self::Metadata, ) -> Option<String>

Programmatically trigger the handling of a JSON-RPC message. TODO: support async

Source

fn metadata_from_sender(sender: UnboundedSender<String>) -> Self::Metadata

Derive an instance of the Self::Metadata associated type from an UnboundedSender.

Source

fn new() -> Self

Create a new instance of a Handler implementation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§