2 unstable releases

0.2.0 Sep 27, 2023
0.1.0 Sep 1, 2023

#2 in #rotor

27 downloads per month

MIT/Apache

7KB
102 lines

Rotors

Latest Version Latest Version Apache 2.0 OR MIT licensed

Rust PROTOcols without the Pain

Why should I use this library?

You probably shouldn't, because this library is under development and has not gone through serious scrutiny yet.

However, if you would like an easier way to use native Rust types inside a tonic project, this might be useful to you.

How should I use this library?

Instead of writing a gRPC xyz.proto file and using the tonic-build tools in your build.rs, you can just use a simple macro in your code, and let the macro do most of the heavy lifting!

use rotors::rotors;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HelloRequest {
    pub name: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HelloReply {
    pub message: String,
}

rotors! {
    package helloworld;

    service Greeter {
        rpc SayHello (super::HelloRequest) returns (super::HelloReply);
    }
}

The rotors!() macro will define two new rust modules, containing the tonic client and server structures. From there onwards, everything will be just like the tonic you are used to, except that you are finally free to write your own enums without the tedious boilerplate required by gRPC.

When should I use this library?

When using rotors you are creating some RPC code that is now NOT COMPATIBLE with gRPC. If this is fine for you, then go for it!

On the other hand, if you are writing a big project, or want to communicate between instances running different versions of your software, or even sofware written in different languages, this crate won't be of much use to you.

Dependencies

~5–6.5MB
~119K SLoC