1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

upgrade to 2.0 alpha.3

This commit is contained in:
Nikolay Kim
2019-12-07 23:59:24 +06:00
parent e7f7175b7b
commit 3127352797
100 changed files with 1075 additions and 1107 deletions

View File

@ -1,10 +1,11 @@
[package]
name = "template_handlebars"
version = "0.1.0"
version = "1.0.0"
authors = ["Alexandru Tiniuc <tiniuc.alexandru@gmail.com>"]
edition = "2018"
[dependencies]
actix-web = "1.0"
actix-web = "2.0.0-alpha.3"
actix-rt = "1.0.0-alpha.3"
handlebars = "2.0.0-beta.2"
serde_json = "1.0"

View File

@ -13,7 +13,7 @@ use std::io;
// Macro documentation can be found in the actix_web_codegen crate
#[get("/")]
fn index(hb: web::Data<Handlebars>) -> HttpResponse {
async fn index(hb: web::Data<Handlebars>) -> HttpResponse {
let data = json!({
"name": "Handlebars"
});
@ -23,7 +23,10 @@ fn index(hb: web::Data<Handlebars>) -> HttpResponse {
}
#[get("/{user}/{data}")]
fn user(hb: web::Data<Handlebars>, info: web::Path<(String, String)>) -> HttpResponse {
async fn user(
hb: web::Data<Handlebars>,
info: web::Path<(String, String)>,
) -> HttpResponse {
let data = json!({
"user": info.0,
"data": info.1
@ -33,7 +36,8 @@ fn user(hb: web::Data<Handlebars>, info: web::Path<(String, String)>) -> HttpRes
HttpResponse::Ok().body(body)
}
fn main() -> io::Result<()> {
#[actix_rt::main]
async fn main() -> io::Result<()> {
// Handlebars uses a repository for the compiled templates. This object must be
// shared between the application threads, and is therefore passed to the
// Application Builder as an atomic reference-counted pointer.
@ -50,5 +54,6 @@ fn main() -> io::Result<()> {
.service(user)
})
.bind("127.0.0.1:8080")?
.run()
.start()
.await
}