#json-rpc #rpc #macro #json

susydev-jsonrpc-macros

为susydev-jsonrpc-core提供的辅助宏

1个稳定版本

使用旧的Rust 2015

10.0.1 2019年3月25日

168#json-rpc 中排名

每月下载量46

MIT许可证

125KB
3K SLoC

susydev_jsonrpc_core的高层次、类型化包装。

允许以类型化的方式创建“服务”对象,将一组RPC方法分组在一起。

示例

extern crate susydev_jsonrpc_core;
#[macro_use] extern crate susydev_jsonrpc_macros;
use susydev_jsonrpc_core::{IoHandler, Error, Result};
use susydev_jsonrpc_core::futures::future::{self, FutureResult};
build_rpc_trait! {
	pub trait Rpc {
		/// Returns a protocol version
		#[rpc(name = "protocolVersion")]
		fn protocol_version(&self) -> Result<String>;

		/// Adds two numbers and returns a result
		#[rpc(name = "add")]
		fn add(&self, u64, u64) -> Result<u64>;

		/// Performs asynchronous operation
		#[rpc(name = "callAsync")]
		fn call(&self, u64) -> FutureResult<String, Error>;
	}
}
struct RpcImpl;
impl Rpc for RpcImpl {
	fn protocol_version(&self) -> Result<String> {
		Ok("version1".into())
	}

	fn add(&self, a: u64, b: u64) -> Result<u64> {
		Ok(a + b)
	}

	fn call(&self, _: u64) -> FutureResult<String, Error> {
		future::ok("OK".to_owned()).into()
	}
}

fn main() {
     let mut io = IoHandler::new();
     let rpc = RpcImpl;

     io.extend_with(rpc.to_delegate());
}

依赖项

~2–3MB
~57K SLoC