GitXplorerGitXplorer
L

syncarp

public
11 stars
2 forks
0 issues

Commits

List of commits on branch main.
Unverified
e46881ce373bdfa6b03da0f07f5b6ffaeacfb9df

Fix some clippy lints.

LLaurentMazare committed 2 years ago
Unverified
67a0373aa9eaac5e6e31af2b24eb5adb7e2c54d0

Fix some clippy lints for rust 1.66.

LLaurentMazare committed 2 years ago
Unverified
f3c3c351a24305620eaeafe9af178adbefde1c9a

Derive some equalities.

LLaurentMazare committed 2 years ago
Unverified
898eb0008a52e30becf98558221103a89555f01e

Removing the shape printing.

LLaurentMazare committed 3 years ago
Unverified
4bf19b0759a22ff74804e6e99c24abc558d5d226

Add some indications to the readme.

LLaurentMazare committed 3 years ago
Unverified
6f6f8d217ef2f1cb45415e08d60f34f9b64e0c53

Update to the latest binprot version.

LLaurentMazare committed 3 years ago

README

The README file for this repository.

syncarp

An async RPC implementation based on tokio and compatible with OCaml Async_rpc.

This uses tokio and relies on binprot-rs for message serialization.

A simple server matching the OCaml example can be implemented as follows:

struct GetUniqueId;
struct GetUniqueIdImpl(Arc<Mutex<i64>>);

impl JRpc for GetUniqueId {
    type Q = ();
    type R = i64;
    const RPC_NAME: &'static str = "get-unique-id";
    const RPC_VERSION: i64 = 0i64;
}

impl syncarp::JRpcImpl for GetUniqueIdImpl {
    type E = std::convert::Infallible;
    type JRpc = GetUniqueId;

    fn rpc_impl(&self, _q: <Self::JRpc as JRpc>::Q) -> Result<<Self::JRpc as JRpc>::R, Self::E> {
        let mut b = self.0.lock().unwrap();
        let result = *b;
        *b += 1;
        Ok(result)
    }
}

#[tokio::main]
async fn main() -> Result<(), syncarp::Error> {
    let get_unique_id_impl = GetUniqueIdImpl(Mutex::new(0));
    syncarp::RpcServer::new("127.0.0.1")
        .await?
        .add_rpc(get_unique_id_impl)
        .run()
        .await?;
    Ok(())
}

Example Client/Server

The examples directory contains a client and a server implementation in Rust as well as their OCaml equivalents. It is possible to start a Rust server and get the OCaml client to connect to it via the following:

# Start the Rust server.
cargo run --example server

# Connect with the OCaml client.
cd examples/ocaml
dune exec ./rpc_client.exe

Or the other way around:

# Start the OCaml server.
cd examples/ocaml
dune exec ./rpc_server.exe

# Connect with the Rust server (to be run from the top directory).
cargo run --example client