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§
Sourcetype Metadata: PubSubMetadata + Unpin + Debug
type Metadata: PubSubMetadata + Unpin + Debug
The type to use as the metadata for the IO handler. Especially relevant for PubSub.
Required Methods§
Sourcefn add_method<F>(&mut self, name: &str, method: F)where
F: RpcMethodSimple,
fn add_method<F>(&mut self, name: &str, method: F)where
F: RpcMethodSimple,
Add a JSON-RPC method.
Sourcefn add_subscription<F, G>(
&mut self,
notification: &str,
subscribe: (&str, F),
unsubscribe: (&str, G),
)
fn add_subscription<F, G>( &mut self, notification: &str, subscribe: (&str, F), unsubscribe: (&str, G), )
Add a JSON-RPC subscription.
Sourcefn as_meta_io_handler(&self) -> MetaIoHandler<Self::Metadata>
fn as_meta_io_handler(&self) -> MetaIoHandler<Self::Metadata>
Cast this down to an instance of MetaIoHandler
.
Sourcefn describe_api(&self) -> Vec<String>
fn describe_api(&self) -> Vec<String>
Get a list of all the supported JSON-RPC methods.
Sourcefn handle_request_sync(
&self,
request: &str,
meta: Self::Metadata,
) -> Option<String>
fn handle_request_sync( &self, request: &str, meta: Self::Metadata, ) -> Option<String>
Programmatically trigger the handling of a JSON-RPC message. TODO: support async
Sourcefn metadata_from_sender(sender: UnboundedSender<String>) -> Self::Metadata
fn metadata_from_sender(sender: UnboundedSender<String>) -> Self::Metadata
Derive an instance of the Self::Metadata
associated type from an UnboundedSender
.
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.