header


Crates.io Crates.io (Downloads) Docs.rs Gitter

Tsukuyomi is a next generation Web framework for Rust.

The ultimate goal of this project is to provide a Web framework for developing the asynchronous and fast Web services, with the help of ecosystem of Rust for asynchronous network services like Tokio and Hyper.

Features

The following features does not currently implemented but will be supported in the future version:

Getting Started

Tsukuyomi requires the latest version of Rust compiler. The required Rust toolchain is 1.27 or higher.

toml [dependencies] tsukuyomi = "0.2" futures = "0.1.22"

```rust,no_run extern crate tsukuyomi; extern crate futures;

use tsukuyomi::{App, Input, Error, Handler}; use futures::Future;

// A synchronous handler function. // It will return a Responder which immediately convert into an HTTP response, // and does not need any asynchronous computation. fn handler(_input: &mut Input) -> &'static str { "Hello, Tsukuyomi.\n" }

// An asynchronous handler function. // It will return a Future representing the remaining computation in the handler. fn asynchandler(input: &mut Input) -> impl Future + Send + 'static { input.bodymut().readall().convertto::() .andthen(|body| { Ok(format!("Received: {}", body)) }) .inspect(|| { // You can access a mutable reference to Input stored in // the task-local storage by using Input::withcurrent(): Input::withcurrent(|input| { println!("[debug] path = {}", input.uri().path()); }) }) }

fn main() -> tsukuyomi::AppResult<()> { let app = App::builder() .mount("/", |m| { m.get("/") .handle(Handler::new_ready(handler));

        m.post("/async")
         .handle(Handler::new_async(async_handler));
    })
    .finish()?;

tsukuyomi::run(app)

} ```

Using futures-await (requires Nightly compiler)

toml [dependencies] tsukuyomi = "0.2" futures-await = "0.1"

```rust,no_run

![feature(procmacro, procmacrononitems, generators)]

extern crate tsukuyomi; extern crate futures_await as futures;

use futures::prelude::{async, await, Future}; use tsukuyomi::{App, Input, Handler};

[async]

fn handler() -> tsukuyomi::Result { let readall = Input::withcurrent(|input| input.bodymut().readall()); let message: String = await!(readall.convertto())?; Ok(format!("Received: {}", message)) }

fn main() -> tsukuyomi::AppResult<()> { let app = App::builder() .mount("/", |m| { m.post("/") .handle(Handler::newfullyasync(handler)); }) .finish()?;

tsukuyomi::run(app)

} ```

More examples are located in examples/.

If you want to experiment with these examples, try to clone this repository and run the following command:

shell-session $ cargo run -p example-basic

Documentation

Build Status

| Travis CI | Appveor | Coveralls | |:---------:|:-------:|:---------:| | Build Status | Build status | Coverage Status |

License

Tsukuyomi is licensed under either of MIT license or Apache License, Version 2.0 at your option.