1
0
mirror of https://github.com/actix/examples synced 2025-02-02 09:39:03 +01:00

Avoid double Arc inside template_handlebars (#147)

This commit is contained in:
Valentin 2019-06-22 09:07:39 +02:00 committed by Nikolay Kim
parent e7ed6755a5
commit 748d4516eb

View File

@ -9,13 +9,11 @@ use actix_web::{App, HttpResponse, HttpServer};
use handlebars::Handlebars; use handlebars::Handlebars;
use std::sync::Arc;
use std::io; use std::io;
// Macro documentation can be found in the actix_web_codegen crate // Macro documentation can be found in the actix_web_codegen crate
#[get("/")] #[get("/")]
fn index(hb: web::Data<Arc<Handlebars>>) -> HttpResponse { fn index(hb: web::Data<Handlebars>) -> HttpResponse {
let data = json!({ let data = json!({
"name": "Handlebars" "name": "Handlebars"
}); });
@ -26,7 +24,7 @@ fn index(hb: web::Data<Arc<Handlebars>>) -> HttpResponse {
#[get("/{user}/{data}")] #[get("/{user}/{data}")]
fn user( fn user(
hb: web::Data<Arc<Handlebars>>, hb: web::Data<Handlebars>,
info: web::Path<(String, String)>, info: web::Path<(String, String)>,
) -> HttpResponse { ) -> HttpResponse {
let data = json!({ let data = json!({
@ -46,7 +44,7 @@ fn main() -> io::Result<()> {
handlebars handlebars
.register_templates_directory(".html", "./static/templates") .register_templates_directory(".html", "./static/templates")
.unwrap(); .unwrap();
let handlebars_ref = web::Data::new(Arc::new(handlebars)); let handlebars_ref = web::Data::new(handlebars);
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()