Skip to content

thehydroimpulse/thrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thrust Build Status

Note: A work in progress. It's not in a useful state right now.

A Rust implementation of the Apache Thrift protocol that simplifies communicating between independent systems that may be implemented in various languages.

Features

  • Scalable Thrift RPC
  • Rust code generator from a .thrift file.
  • Built on-top of Asynchronous I/O via Mio.
  • Heavily uses Futures to manage asynchronous code.
  • Multiplexing multiple RPC services on a single event-loop.
  • Automatically spawn an EventLoop per CPU core.

Installing

[dependencies]
thrust = "*"

You may also want to install the code generator using Cargo:

cargo install thrust

Generating Rust Code

Thrust comes with a thrust binary that compiles your .thrift files into Rust code.

thrust hello.thrift .

The first argument is the input thrift file and the second is the path where you want your Rust file to be written to. The filename will be based on the Rust namespace in your thrift file namespace rust <name>.

Spawning Event Loops

use thrust::Spawner;

fn main() {
  // By default, this will run as many event loop threads as you have CPU cores.
  let spawner = Spawner::new(None);

  // ...

  // Block the main thread until all event loops terminate.
  spawner.join();
}

Creating a Thrift Service

Thrust supports creating Thrift services, backed by non-blocking TCP sockets with Mio.

namespace rust thrift;
// Start by defining a service in your Thrift file.
service Flock {
  bool isLoggedIn(1: string token);
}

After using Thrust to generate the service in Rust, we can start using it.

extern crate thrust;
// Tangle is a futures implementation
extern crate tangle;

// The generated Rust module.
use thrift::Flock;

use thrust::{Spawner, Server};
use tangle::{Future, Async};

pub struct FlockService;

impl Flock for FlockService {
  fn isLoggedIn(&mut self, token: String) -> Future<bool> {
    if &*token == "123" {
      Async::Ok(true)
    } else {
      Async::Ok(false)
    }
  }
}

fn main() {
  // Create a Spawner to manage Mio event loops.
  let mut spawner = Spawner::new(None);

  Server::run(&spawner, FlockService);

  spawner.join();
}

License

MIT — go ham!

About

Unmaintained http://thehydroimpulse.github.io/thrust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages