use jsonrpc_core::{IoHandler, Error, Result}; use jsonrpc_core::futures::future::{self, FutureResult}; use jsonrpc_derive::rpc; #[rpc] pub trait Rpc { /// Returns a protocol version #[rpc(name = "protocolVersion")] fn protocol_version(&self) -> Result; /// Adds two numbers and returns a result #[rpc(name = "add", alias("callAsyncMetaAlias"))] fn add(&self, _: u64, _: u64) -> Result; /// Performs asynchronous operation #[rpc(name = "callAsync")] fn call(&self, _: u64) -> FutureResult; } struct RpcImpl; impl Rpc for RpcImpl { fn protocol_version(&self) -> Result { Ok("version1".into()) } fn add(&self, a: u64, b: u64) -> Result { Ok(a + b) } fn call(&self, _: u64) -> FutureResult { future::ok("OK".to_owned()) } } fn main() { let mut io = IoHandler::new(); let rpc = RpcImpl; io.extend_with(rpc.to_delegate()) }