minghuaw / toy-rpc

An async RPC in rust-lang that mimics golang's net/rpc
25 stars 3 forks source link
async async-std rpc rpc-framework rust tokio

toy-rpc

An async RPC crate that mimics the golang's net/rpc package and supports both async-std and tokio.

This project is still being actively developed. I have kind of run out of ideas for features, so feel free to let me know if there is a feature that you want.

Crates.io version docs.rs docs Download Unsafe Rust forbidden

toy-rpc aims to be an easy-to-use async RPC tool that is inspired by golang's net/rpc's API. It supports both async_std and tokio runtimes over either TCP or TLS. Integration with common HTTP server frameworks such as actix_web, warp and tide are provided.

The overall usage and API should feel similar to that of the golang's net/rpc package. Some of the names are changed to make them sound more "rusty". Because rust does not come with runtime reflection, attribute macros #[export_impl] and #[export_trait] / #[export_trait_impl], and attribute #[export_method] are used to mark functions "exported" in golang's net/rpc perspective.

Some other features of toy-rpc:

More detailed usage can be found in the book and documentation.

This crate uses #![forbid(unsafe_code)] to ensure no usage of unsafe in the crate.

Feature flags

The feature flags can be put into three categories.

Choice of runtime and HTTP framework integration

Choice of RPC server or client (both can be enabled at the same time)

Choice of serialization/deserialzation (only one should be enabled at a time)

WebSocket support (HTTP integration is implementd with WebSocket)

TLS support

Other trivial feature flags are listed below, and they are likely of no actual usage for you.

By default, only serde_bincode feature is enabled. You must enable at least one runtime feature flag and the server and/or client to have something usable.

Default features

default = ["serde_bincode"]

Integration

HTTP integration is provided for actix-web, tide, and warp. More details can be found in the Book/Integrations and in examples.

Quickstart Example

A quickstart example with tokio runtime is provided in the Book/Quickstart.

License: MIT/Apache-2.0