#rpc #async-std #async #rpc-server #rpc-api #rpc-client #tokio

toy-rpc

An async RPC that mimics golang net/rpc's usage and supports both async-std and tokio

52 releases

0.10.0 Apr 19, 2024
0.9.0-beta.1 Aug 18, 2022
0.9.0-alpha.2 Nov 24, 2021
0.8.6 Jul 19, 2022
0.3.1 Nov 27, 2020

#1486 in Network programming

Download history 280/week @ 2024-07-21 559/week @ 2024-07-28 183/week @ 2024-08-04 121/week @ 2024-08-11 118/week @ 2024-08-18 122/week @ 2024-08-25 217/week @ 2024-09-01 137/week @ 2024-09-08 137/week @ 2024-09-15 274/week @ 2024-09-22 126/week @ 2024-09-29 126/week @ 2024-10-06 192/week @ 2024-10-13 86/week @ 2024-10-20 84/week @ 2024-10-27 148/week @ 2024-11-03

537 downloads per month

MIT/Apache

305KB
6.5K SLoC

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.

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:

  • Cascading cancellation: whenever an unfinished Call<Res> is dropped, a cancellation will be sent to the server and thus propagating the cancellation.

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

  • async_std_runtime: supports usage with async-std
  • tokio_runtime: supports usage with tokio
  • http_tide: enables tide integration on the server side. This also enables async_std_runtime and ws_async_std
  • http_actix_web: enables actix-web integration on the server side. This also enables tokio_runtime and ws_tokio
  • http_warp: enables integration with warp on the server side. This also enables tokio_runtime and ws_tokio
  • http_axum: enables integration with axum on the server side. This also enables tokio_runtime and ws_tokio

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

  • server: enables RPC server
  • client: enables RPC client

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

  • serde_bincode: (default) the default codec will use bincode for serialization/deserialization
  • serde_json: the default codec will use serde_json for json serialization/deserialization
  • serde_cbor: the default codec will use serde_cbor for serialization/deserialization
  • serde_rmp: the default codec will use rmp-serde for serialization/deserialization

WebSocket support (HTTP integration is implementd with WebSocket)

  • ws_tokio: enables WebSocket and HTTP integrations with tokio. This must be enabled for client to use dial_http(addr) or dial_websocket(addr).
  • ws_async_std: enables WebSocket and HTTP integrations with async-std. This must be enabled for client to use dial_http(addr) or dial_websocket(addr).

TLS support

  • tls: enables TLS support

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

  • docs
  • std: 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"]

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

Dependencies

~4–19MB
~278K SLoC