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 } }