aboutsummaryrefslogtreecommitdiff

urpc

A minimalistic RPC framework for Rust, designed for simplicity and performance.

Features

  • Async/await support
  • TCP and Unix socket transport
  • Procedural macros for service definitions
  • Serialization with bincode
  • Lightweight and fast

Example

use urpc::*;

#[urpc::service]
trait Hello {
    type Error = ();

    async fn hello(name: String) -> String;
}

struct HelloServer;

impl Hello for HelloServer {
    async fn hello(&self, _ctx: urpc::Context, name: String) -> Result<String, ()> {
        Ok(format!("Hello, {}!", name))
    }
}

#[tokio::main]
async fn main() {
    // Server
    let listener = urpc::tcp::bind("127.0.0.1:8080").await.unwrap();

    tokio::spawn(async move {
        urpc::Server::default()
            .with_listener(listener)
            .with_service(HelloServer.into_service())
            .serve()
            .await
    });

    // Client
    let channel = urpc::ClientChannel::new(
        urpc::tcp::connect("127.0.0.1:8080").await.unwrap()
    );
    let client = HelloClient::new(channel);

    let response = client.hello("World".to_string()).await.unwrap();
    println!("{}", response); // "Hello, World!"
}

License

Licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.