Rust implementation of openrpc Specification
- openrpc-schema
Implement the schema of openrpc. Support to generate openrpc schema documents with the basic functions.
- openrpc-derive
Implement a proc macro to generate openrpc schema for rust traits.
Baisc Usage
use jsonrpc_core::Error;
use openrpc_derive::openrpc;
#[openrpc]
pub trait DebugApi {
#[rpc(name = "debug.panic")]
fn panic(&self, me: String) -> Result<String, Error>;
#[rpc(name = "debug.sleep")]
fn sleep(&self, time: u64) -> Result<String, Error>;
}
fn main() {
let schema = self::gen_schema();
let j = serde_json::to_string_pretty(&schema).unwrap();
println!("{}", j);
}
Works with jsonrpc compatibly by adding the “jsonrpc” to the [features] section.
openrpc-derive = {git = "https://github.com/starcoinorg/openrpc-rs",features=["jsonrpc"]}
This can generate both jsonrpc client and server, and openrpc schema.