Struct tsukuyomi::Handler [−][src]
pub struct Handler(_);
A type for wrapping the handler function used in the framework.
Methods
impl Handler
[src]
impl Handler
pub fn new_ready<R>(
handler: impl Fn(&mut Input) -> R + Send + Sync + 'static
) -> Handler where
R: Responder,
[src]
pub fn new_ready<R>(
handler: impl Fn(&mut Input) -> R + Send + Sync + 'static
) -> Handler where
R: Responder,
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();
pub fn new_async<R>(
handler: impl Fn(&mut Input) -> R + Send + Sync + 'static
) -> Handler where
R: Future + Send + 'static,
R::Item: Responder,
Error: From<R::Error>,
[src]
pub fn new_async<R>(
handler: impl Fn(&mut Input) -> R + Send + Sync + 'static
) -> Handler where
R: Future + Send + 'static,
R::Item: Responder,
Error: From<R::Error>,
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();
pub fn new_fully_async<R>(
handler: impl Fn() -> R + Send + Sync + 'static
) -> Handler where
R: Future + Send + 'static,
R::Item: Responder,
Error: From<R::Error>,
[src]
pub fn new_fully_async<R>(
handler: impl Fn() -> R + Send + Sync + 'static
) -> Handler where
R: Future + Send + 'static,
R::Item: Responder,
Error: From<R::Error>,
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();
pub fn handle(&self, input: &mut Input) -> Handle
[src]
pub fn handle(&self, input: &mut Input) -> Handle
Calls the underlying handler function with the provided reference to Input
.
Trait Implementations
impl Debug for Handler
[src]
impl Debug for Handler
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
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]
impl<F> From<F> for Handler where
F: Fn(&mut Input) -> Handle + Send + Sync + 'static,