Skip to content
/ tarpc Public
forked from google/tarpc

An RPC framework for Rust with a focus on ease of use.

License

Notifications You must be signed in to change notification settings

vhdirk/tarpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tarpc: Tim & Adam's RPC lib

Travis-CI Status Coverage Status Software License Latest Version

Disclaimer: This is not an official Google product.

tarpc is an RPC framework for rust with a focus on ease of use. Defining a service can be done in just a few lines of code, and most of the boilerplate of writing a server is taken care of for you.

Documentation

Example

#[macro_use]
extern crate tarpc;

mod hello_service {
    service! {
        rpc hello(name: String) -> String;
    }
}

struct HelloService;
impl hello_service::Service for HelloService {
    fn hello(&self, name: String) -> String {
        format!("Hello, {}!", s)
    }
}

fn main() {
    let server_handle = hello_service::serve("0.0.0.0:0", HelloService, None).unwrap();
    let client = hello_service::Client::new(server_handle.local_addr(), None).unwrap();
    assert_eq!("Hello, Mom!".into(), client.hello("Mom".into()).unwrap());
    drop(client);
    server_handle.shutdown();
}

The service! macro expands to a collection of items that collectively form an rpc service. In the above example, the macro is called within the hello_service module. This module will contain a Client type, a Service trait, and a serve function. serve can be used to start a server listening on a tcp port. A Client can connect to such a service. Any type implementing the Service trait can be passed to serve. These generated types are specific to the echo service, and make it easy and ergonomic to write servers without dealing with sockets or serialization directly. See the tarpc_examples package for more sophisticated examples.

Additional Features

  • Concurrent requests from a single client.
  • Attributes can be specified on rpc methods. These will be included on both the Service trait methods as well as on the Client's stub methods.
  • Just like regular fns, the return type can be left off when it's -> ().
  • Arg-less rpc's are also allowed.

Planned Improvements (actively being worked on)

  • Automatically reconnect on the client side when the connection cuts out.
  • Support asynchronous server implementations (currently thread per connection).
  • Support generic serialization protocols.

Contributing

To contribute to tarpc, please see CONTRIBUTING.

License

tarpc is distributed under the terms of the MIT license.

See LICENSE for details.

About

An RPC framework for Rust with a focus on ease of use.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 96.5%
  • Shell 3.5%