extern crate serde; #[macro_use] extern crate serde_derive; extern crate jsonrpc_core; extern crate jsonrpc_pubsub; #[macro_use] extern crate jsonrpc_derive; use std::sync::Arc; use jsonrpc_core::Result; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, Session, PubSubHandler}; #[rpc] pub trait Rpc { type Metadata; /// Hello subscription #[pubsub(subscription = "hello", subscribe, name = "hello_subscribe", alias("hello_sub"))] fn subscribe(&self, _: Self::Metadata, _: Subscriber); /// Unsubscribe from hello subscription. #[pubsub(subscription = "hello", unsubscribe, name = "hello_unsubscribe")] fn unsubscribe(&self, _: Option, _: SubscriptionId) -> Result; } // One way serialization #[derive(Serialize)] struct SerializeOnly { foo: String, } struct RpcImpl; impl Rpc for RpcImpl { type Metadata = Arc; fn subscribe(&self, _: Self::Metadata, _: Subscriber) { unimplemented!(); } fn unsubscribe(&self, _: Option, _: SubscriptionId) -> Result { unimplemented!(); } } fn main() { let mut io = PubSubHandler::default(); let rpc = RpcImpl; io.extend_with(rpc.to_delegate()); }