json rpc

JSON-RPC 2.0 server implementation in Rust

Example

full example

```rust

[json_rpc]

fn greet(name: String) -> Result { Ok(format!("Hello {}", name)) }

struct System;

[json_rpc]

impl System { fn time() -> Result { SystemTime::now().durationsince(UNIXEPOCH).map(|v| v.assecs()).maperr(|| jsonrpcv2::Error::servererror()) }

async fn issue() -> Result<String, json_rpc_v2::Error> {
    read_to_string("/etc/issue").await.map_err(|_| json_rpc_v2::Error::server_error())
}

}

[tokio::main]

async fn main() -> Result<(), Box> { let mut registry = Registry::new(); registry.register_method("greet", greet); registry.register::();

let _ = registry.call(br#"{"jsonrpc":"2.0","method":"greet","params":["foo"],"id":1}"#).await;
let _ = registry.call(br#"{"jsonrpc":"2.0","method":"system.time","params":[],"id":1}"#).await;
let _ = registry.call(br#"{"jsonrpc":"2.0","method":"system.issue","params":[],"id":1}"#).await;
Ok(())

} ```