3个版本
0.1.2 | 2023年3月29日 |
---|---|
0.1.1 | 2022年10月8日 |
0.1.0 | 2022年10月8日 |
#830 in 异步
每月25次下载
39KB
804 行
海盗!
Rust ArrrrPC 库
Pirates,一个简单直观的接口,用于异步Rust程序中提供和调用RPC
定义RPC
pub struct AddName {}
#[pirates::rpc_definition]
impl AddName {
fn name() -> RpcId {
RpcId::AddName
}
fn implement(state: &mut ServerState, query: String) -> RpcResult<()> {
state.names.push(query);
Ok(())
}
}
提供服务
let mut server = RpcServer::new(state.clone());
server.add_rpc(Box::new(rpcs::AddName::server()));
调用它
let addr = "200.1.3.7:5959";
let name = String::from("Gaspode the wonder dog");
pirates::call_client(addr, name, rpcs::AddName::client()).await;
let names = call_client(addr, (), rpcs::GetNames::client()).await;
assert_eq!(vec![String::from("Gaspode the wonder dog")], names);
文档
文档可在docs.rs上找到
示例
示例“名称服务器”在example/
中可用。这会产生一个CLI二进制文件,您可以使用它来托管服务器,然后单独查询它以添加和打印名称。有关更多信息,请参阅该目录中的README。
待办事项
- 更多示例?
许可证
Apache-2.0 或 MIT
依赖项
~4–16MB
~149K SLoC