Introduction
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.
Minimum supported Rust version: 1.53 or later
Why?
While there are grpc implementations like grpc-rs and tonic as well as schema-free crates like tarpc, I didn't find
a crate that offers the same level of ease-of-use as that of the golang's net/rpc package. Other than the ease-of-use,
not many async RPC crates work with both async_std and tokio runtime and could be difficult to integrate with the common
async HTTP crates (actix_web, warp, and tide). Thus I started working on this crate to bring something that is
easy-to-use and supports both async_std and tokio runtimes.
Feature flags
Most of the feature flags can be put into three categories.
Choice of runtime and HTTP framework integration
async_std_runtime: supports usage withasync-stdtokio_runtime: supports usage withtokiohttp_tide: enablestideintegration on the server side. This also enablesasync_std_runtimeandws_async_stdhttp_actix_web: enablesactix-webintegration on the server side. This also enablestokio_runtimeandws_tokiohttp_warp: enables integration withwarpon the server side. This also enablestokio_runtimeandws_tokiohttp_axum: enables integration withaxumon the server side. This also enablestokio_runtimeandws_tokio
Choice of RPC server or client (both can be enabled at the same time)
server: enables RPC serverclient: enables RPC client. Please note thatwsmust also be enabled for client to usedial_http(addr)ordial_websocket(addr).
Choice of serialization/deserialzation (only one should be enabled at a time)
serde_bincode: (default) the default codec will usebincodefor serialization/deserializationserde_json: the default codec will useserde_jsonforjsonserialization/deserializationserde_cbor: the default codec will useserde_cborfor serialization/deserializationserde_rmp: the default codec will usermp-serdefor serialization/deserialization
WebSocket support (HTTP integration is implemented using WebSocket)
ws_tokio: enables WebSocket and HTTP integrations withtokio. This must be enabled for client to usedial_http(addr)ordial_websocket(addr)withtokio_runtime.ws_async_std: enables WebSocket and HTTP integrations withasync-std. This must be enabled for client to usedial_http(addr)ordial_websocket(addr)withasync_std_runtime.
TLS support
tls: enables TLS support
Convenience conversion to anyhow::Error
anyhow: enables usinganyhow::Errorin RPC methods
Other trivial feature flags are listed below, and they are likely of no actual usage for you.
docsstd:serde/std. There is no actual usage right now.
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",
]