Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.19 KB

README.org

File metadata and controls

40 lines (30 loc) · 1.19 KB

openrpc-rs

Rust implementation of openrpc Specification

Sub projects

  • 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.

Examples

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.