Struct tsukuyomi::Handler[][src]

pub struct Handler(_);

A type for wrapping the handler function used in the framework.

Methods

impl Handler
[src]

Creates a Handler from the provided function.

The provided handler is fully synchronous, which means that the provided handler will return a result and immediately converted into an HTTP response without polling the asynchronous status.

Examples

fn index(input: &mut Input) -> &'static str {
    "Hello, Tsukuyomi.\n"
}

let router = Router::builder()
    .mount("/", |m| {
        m.get("/index.html").handle(Handler::new_ready(index));
    })
    .finish();

Creates a Handler from the provided function.

The provided handler is partially asynchronous, which means that the handler will process some tasks by using the provided reference to Input and return a future for processing the remaining task.

Examples

fn handler(input: &mut Input) -> impl Future<Item = String, Error = Error> + Send + 'static {
    let query = input.uri().query().unwrap_or("<empty>").to_owned();
    lazy(move || {
        Ok(format!("query = {}", query))
    })
}

let router = Router::builder()
    .mount("/", |m| {
        m.get("/posts").handle(Handler::new_async(handler));
    })
    .finish();

Creates a Handler from the provided async function.

The provided handler is fully asynchronous, which means that the handler will do nothing and immediately return a future which will be resolved as a value to be converted into an HTTP response.

Examples

fn handler() -> impl Future<Item = &'static str, Error = Error> + Send + 'static {
    lazy(|| {
        Ok("Hello, Tsukuyomi.\n")
    })
}

// uses upcoming async/await syntax
// async fn handler() -> &'static str {
//    "Hello, Tsukuyomi.\n"
// }

let router = Router::builder()
    .mount("/", |m| {
        m.get("/posts").handle(Handler::new_fully_async(handler));
    })
    .finish();

Calls the underlying handler function with the provided reference to Input.

Trait Implementations

impl Debug for Handler
[src]

Formats the value using the given formatter. Read more

impl<F> From<F> for Handler where
    F: Fn(&mut Input) -> Handle + Send + Sync + 'static, 
[src]

Performs the conversion.

Auto Trait Implementations

impl Send for Handler

impl Sync for Handler