1
0
mirror of https://github.com/actix/actix-website synced 2024-11-28 18:32:39 +01:00
actix-website/examples/async-handlers/src/main.rs

26 lines
705 B
Rust
Raw Normal View History

2019-06-15 22:37:08 +02:00
mod async_stream;
mod stream;
// <main>
use actix_web::{App, AsyncResponder, Error, HttpRequest, HttpResponse};
use futures::future::{result, Future};
fn index(_req: &HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
result(Ok(HttpResponse::Ok()
.content_type("text/html")
.body(format!("Hello!"))))
.responder()
}
fn index2(_req: &HttpRequest) -> Box<Future<Item = &'static str, Error = Error>> {
result(Ok("Welcome!")).responder()
}
fn main() {
App::new()
.resource("/async", |r| r.route().a(index))
.resource("/", |r| r.route().a(index2))
// .resource("/", |r| r.route().f(async_stream::index))
.finish();
}
// </main>