From 6c3d8b87384c1e375c4b1eb5dc4a27d839942a9d Mon Sep 17 00:00:00 2001 From: Davide Di Carlo Date: Mon, 13 May 2019 05:04:08 +0200 Subject: [PATCH] Make JsonConfig send (#830) * replace Rc with Arc * add Send trait requirement for Fn in JsonConfig error handler * add Sync trait requirement for Fn in JsonConfig error handler * use associated type inside JsonConfig * fix lint: members in the impl has the same order in the trait * Update CHANGES.md --- CHANGES.md | 6 ++++-- src/types/json.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dedf07585..67a97f143 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +### Changes + +* `JsonConfig` is now `Send + Sync`, this implies that `error_handler` must be `Send + Sync` too. + ## [1.0.0-beta.4] - 2019-05-12 ### Add @@ -9,10 +13,8 @@ ### Changes * `App::configure` take an `FnOnce` instead of `Fn` - * Upgrade actix-net crates - ## [1.0.0-beta.3] - 2019-05-04 ### Added diff --git a/src/types/json.rs b/src/types/json.rs index 73614d87e..4e827942f 100644 --- a/src/types/json.rs +++ b/src/types/json.rs @@ -1,6 +1,6 @@ //! Json extractor/responder -use std::rc::Rc; +use std::sync::Arc; use std::{fmt, ops}; use bytes::BytesMut; @@ -168,15 +168,15 @@ impl FromRequest for Json where T: DeserializeOwned + 'static, { - type Config = JsonConfig; type Error = Error; type Future = Box>; + type Config = JsonConfig; #[inline] fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future { let req2 = req.clone(); let (limit, err) = req - .app_data::() + .app_data::() .map(|c| (c.limit, c.ehandler.clone())) .unwrap_or((32768, None)); @@ -236,7 +236,7 @@ where #[derive(Clone)] pub struct JsonConfig { limit: usize, - ehandler: Option Error>>, + ehandler: Option Error + Send + Sync>>, } impl JsonConfig { @@ -249,9 +249,9 @@ impl JsonConfig { /// Set custom error handler pub fn error_handler(mut self, f: F) -> Self where - F: Fn(JsonPayloadError, &HttpRequest) -> Error + 'static, + F: Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync + 'static, { - self.ehandler = Some(Rc::new(f)); + self.ehandler = Some(Arc::new(f)); self } }