An RPC library for Rust.
Example usage:
#[macro_use] extern crate tarpc;
mod my_server {
service! {
rpc hello(name: String) -> String;
rpc add(x: i32, y: i32) -> i32;
}
}
use self::my_server::*;
use std::time::Duration;
struct Server;
impl my_server::Service for Server {
fn hello(&self, s: String) -> String {
format!("Hello, {}!", s)
}
fn add(&self, x: i32, y: i32) -> i32 {
x + y
}
}
fn main() {
let addr = "127.0.0.1:9000";
let shutdown = Server.spawn(addr).unwrap();
let client = Client::new(addr).unwrap();
assert_eq!(3, client.add(1, 2).unwrap());
assert_eq!("Hello, Mom!".to_string(),
client.hello("Mom".to_string()).unwrap());
drop(client);
shutdown.shutdown();
}