GithubHelp home page GithubHelp logo

rzs840707 / tarpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google/tarpc

0.0 3.0 0.0 3.09 MB

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

Home Page: https://google.github.io/tarpc

License: MIT License

Shell 10.40% Rust 89.60%

tarpc's Introduction

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

What is an RPC framework?

"RPC" stands for "Remote Procedure Call," a function call where the work of producing the return value is being done somewhere else. When an rpc function is invoked, behind the scenes the function contacts some other process somewhere and asks them to compute the function instead. The original function then returns the value produced by that other server.

More information

Usage

Add to your Cargo.toml dependencies:

tarpc = "0.3.0"

Example

#[macro_use]
extern crate tarpc;

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

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

fn main() {
    let server_handle = HelloServer.spawn("0.0.0.0:0").unwrap();
    let client = hello_service::Client::new(server_handle.local_addr()).unwrap();
    assert_eq!("Hello, Mom!", 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 (and AsyncClient) type, and a Service trait. The trait provides default fns for starting the service: spawn and spawn_with_config, which start the service listening on a tcp port. A Client (or AsyncClient) can connect to such a service. These generated types make it easy and ergonomic to write servers without dealing with sockets or serialization directly. See the tarpc_examples package for more sophisticated examples.

Documentation

Use cargo doc as you normally would to see the documentation created for all items expanded by a service! invocation.

Additional Features

  • Concurrent requests from a single client.
  • Any type that impls serde's Serialize and Deserialize can be used in the rpc signatures.
  • 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.

tarpc's People

Contributors

tikue avatar shaladdle avatar aawright avatar gsquire avatar bowbaq avatar

Watchers

AndyRen avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.