nanorpc: magic library for a JSON-RPC 2.0 subset (WIP)

Motivation

Typically, writing a client-server networked API (say, a REST API) involves the following three steps:

This is annoying and error-prone. The protocol is essentially specified three times in three different places and ways, and keeping them in sync is a huge chore.

Instead, we want to specify the protocol once, then automatically have:

About nanorpc

nanorpc does exactly. It is a JSON-RPC subset implementation with a macro, #[nanorpc_derive], that given a trait representing the API interface, abstracts away all the duplicate parts of implementing an API.

In particular:

For example:

```rust

[nanorpc_derive]

[async_trait]

pub trait MathProtocol { /// Adds two numbers. Arguments and return type must be JSON-serializable through serde_json async fn add(&self, x: f64, y: f64) -> f64; /// Multiplies two numbers async fn mult(&self, x: f64, y: f64) -> f64; }

// Autogenerates a server struct: pub struct MathService(pub T);

[async_trait]

impl RpcService for MathService { //... }

// Autogenerates a client struct like: pub struct MathClient(pub T);

impl MathClient { /// Adds two numbers pub async fn add(&self, x: f64, y: f64) -> Result;

//...

} ```

At the JSON level, the above protocol will respond to a JSON-RPC 2.0 request like:

{"jsonrpc": "2.0", "method": "mult", "params": [42, 23], "id": 1}

with

{"jsonrpc": "2.0", "result": 966, "id": 1}