1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

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
This commit is contained in:
Davide Di Carlo 2019-05-13 05:04:08 +02:00 committed by Nikolay Kim
parent 5a90e33bcc
commit 6c3d8b8738
2 changed files with 10 additions and 8 deletions

View File

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

View File

@ -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<T> FromRequest for Json<T>
where
T: DeserializeOwned + 'static,
{
type Config = JsonConfig;
type Error = Error;
type Future = Box<Future<Item = Self, Error = Error>>;
type Config = JsonConfig;
#[inline]
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
let req2 = req.clone();
let (limit, err) = req
.app_data::<JsonConfig>()
.app_data::<Self::Config>()
.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<Rc<Fn(JsonPayloadError, &HttpRequest) -> Error>>,
ehandler: Option<Arc<dyn Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync>>,
}
impl JsonConfig {
@ -249,9 +249,9 @@ impl JsonConfig {
/// Set custom error handler
pub fn error_handler<F>(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
}
}