From 1d6ccff3e8a6dbed5537fc6a9f3f65e0a5030e6c Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 29 Dec 2019 03:36:24 +0900 Subject: [PATCH] Update static-files --- content/docs/static-files.md | 4 ++-- examples/static-files/Cargo.toml | 5 +++-- examples/static-files/src/configuration.rs | 10 +++++----- examples/static-files/src/configuration_two.rs | 8 ++++---- examples/static-files/src/directory.rs | 8 ++++---- examples/static-files/src/main.rs | 10 +++++----- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/content/docs/static-files.md b/content/docs/static-files.md index f3512d5..6f9c09c 100644 --- a/content/docs/static-files.md +++ b/content/docs/static-files.md @@ -44,5 +44,5 @@ The Configuration can also be applied to directory service: {{< include-example example="static-files" file="configuration_two.rs" section="config-two" >}} -[showfileslisting]: https://docs.rs/actix-files/0.1.2/actix_files/struct.Files.html -[indexfile]: https://docs.rs/actix-files/0.1.2/actix_files/struct.Files.html#method.index_file +[showfileslisting]: https://docs.rs/actix-files/0.2/actix_files/struct.Files.html +[indexfile]: https://docs.rs/actix-files/0.2/actix_files/struct.Files.html#method.index_file diff --git a/examples/static-files/Cargo.toml b/examples/static-files/Cargo.toml index 8018328..e37f205 100644 --- a/examples/static-files/Cargo.toml +++ b/examples/static-files/Cargo.toml @@ -4,6 +4,7 @@ version = "1.0.0" edition = "2018" [dependencies] -actix-web = "1.0" -actix-files = "0.1" +actix-web = "2.0" +actix-rt = "1.0" +actix-files = "0.2" mime = "*" diff --git a/examples/static-files/src/configuration.rs b/examples/static-files/src/configuration.rs index 54b5d2a..db663d0 100644 --- a/examples/static-files/src/configuration.rs +++ b/examples/static-files/src/configuration.rs @@ -3,7 +3,7 @@ use actix_files as fs; use actix_web::http::header::{ContentDisposition, DispositionType}; use actix_web::{web, App, Error, HttpRequest, HttpServer}; -fn index(req: HttpRequest) -> Result { +async fn index(req: HttpRequest) -> Result { let path: std::path::PathBuf = req.match_info().query("filename").parse().unwrap(); let file = fs::NamedFile::open(path)?; Ok(file @@ -14,11 +14,11 @@ fn index(req: HttpRequest) -> Result { })) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/static-files/src/configuration_two.rs b/examples/static-files/src/configuration_two.rs index 669e625..11b01b3 100644 --- a/examples/static-files/src/configuration_two.rs +++ b/examples/static-files/src/configuration_two.rs @@ -2,7 +2,8 @@ use actix_files as fs; use actix_web::{App, HttpServer}; -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service( fs::Files::new("/static", ".") @@ -10,9 +11,8 @@ pub fn main() { .use_last_modified(true), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/static-files/src/directory.rs b/examples/static-files/src/directory.rs index 6da7ea4..db3131b 100644 --- a/examples/static-files/src/directory.rs +++ b/examples/static-files/src/directory.rs @@ -2,13 +2,13 @@ use actix_files as fs; use actix_web::{App, HttpServer}; -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service(fs::Files::new("/static", ".").show_files_listing()) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/static-files/src/main.rs b/examples/static-files/src/main.rs index a30d5db..ae903b0 100644 --- a/examples/static-files/src/main.rs +++ b/examples/static-files/src/main.rs @@ -7,18 +7,18 @@ use actix_files::NamedFile; use actix_web::{HttpRequest, Result}; use std::path::PathBuf; -fn index(req: HttpRequest) -> Result { +async fn index(req: HttpRequest) -> Result { let path: PathBuf = req.match_info().query("filename").parse().unwrap(); Ok(NamedFile::open(path)?) } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| App::new().route("/{filename:.*}", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } //