From daa5ff77c012d915b9e286ef84e8171e46b44184 Mon Sep 17 00:00:00 2001 From: Sam Samai Date: Mon, 20 Sep 2021 20:55:22 +1000 Subject: [PATCH] Define SharedState type --- examples/actix_example/src/main.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/examples/actix_example/src/main.rs b/examples/actix_example/src/main.rs index e0e2a50c..2e392620 100644 --- a/examples/actix_example/src/main.rs +++ b/examples/actix_example/src/main.rs @@ -2,17 +2,12 @@ use std::sync::Arc; use actix_files as fs; -use actix_http::{body::Body, Response}; -use actix_web::dev::ServiceResponse; -use actix_web::http::StatusCode; -use actix_web::middleware::errhandlers::{ErrorHandlerResponse, ErrorHandlers}; use actix_web::{ - delete, error, get, guard, http, middleware, post, web, App, Error, HttpRequest, HttpResponse, + error, get, middleware, post, web, App, Error, HttpRequest, HttpResponse, HttpServer, Result, }; use listenfd::ListenFd; use sea_orm::entity::*; -use sea_orm::query::*; use sea_orm::{DatabaseConnection, EntityTrait}; use serde::{Deserialize, Serialize}; use std::env; @@ -29,6 +24,7 @@ struct AppState { templates: tera::Tera, conn: Arc, } +type SharedState = Arc; #[derive(Debug, Deserialize)] pub struct Params { @@ -45,7 +41,7 @@ struct FlashData { #[get("/")] async fn list( req: HttpRequest, - data: web::Data>, + data: web::Data, opt_flash: Option>, ) -> Result { let template = &data.templates; @@ -81,7 +77,7 @@ async fn list( } #[get("/new")] -async fn new(data: web::Data>) -> Result { +async fn new(data: web::Data) -> Result { let template = &data.templates; let ctx = tera::Context::new(); let body = template @@ -92,7 +88,7 @@ async fn new(data: web::Data>) -> Result { #[post("/")] async fn create( - data: web::Data>, + data: web::Data, post_form: web::Form, ) -> actix_flash::Response { let conn = &data.conn; @@ -117,7 +113,7 @@ async fn create( } #[get("/{id}")] -async fn edit(data: web::Data>, id: web::Path) -> Result { +async fn edit(data: web::Data, id: web::Path) -> Result { let conn = &data.conn; let template = &data.templates; @@ -138,7 +134,7 @@ async fn edit(data: web::Data>, id: web::Path) -> Result>, + data: web::Data, id: web::Path, post_form: web::Form, ) -> actix_flash::Response { @@ -164,7 +160,7 @@ async fn update( #[post("/delete/{id}")] async fn delete( - data: web::Data>, + data: web::Data, id: web::Path, ) -> actix_flash::Response { let conn = &data.conn;