mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 10:42:55 +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:
parent
5a90e33bcc
commit
6c3d8b8738
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# 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
|
## [1.0.0-beta.4] - 2019-05-12
|
||||||
|
|
||||||
### Add
|
### Add
|
||||||
@ -9,10 +13,8 @@
|
|||||||
### Changes
|
### Changes
|
||||||
|
|
||||||
* `App::configure` take an `FnOnce` instead of `Fn`
|
* `App::configure` take an `FnOnce` instead of `Fn`
|
||||||
|
|
||||||
* Upgrade actix-net crates
|
* Upgrade actix-net crates
|
||||||
|
|
||||||
|
|
||||||
## [1.0.0-beta.3] - 2019-05-04
|
## [1.0.0-beta.3] - 2019-05-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Json extractor/responder
|
//! Json extractor/responder
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::sync::Arc;
|
||||||
use std::{fmt, ops};
|
use std::{fmt, ops};
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
@ -168,15 +168,15 @@ impl<T> FromRequest for Json<T>
|
|||||||
where
|
where
|
||||||
T: DeserializeOwned + 'static,
|
T: DeserializeOwned + 'static,
|
||||||
{
|
{
|
||||||
type Config = JsonConfig;
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self, Error = Error>>;
|
type Future = Box<Future<Item = Self, Error = Error>>;
|
||||||
|
type Config = JsonConfig;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
let req2 = req.clone();
|
let req2 = req.clone();
|
||||||
let (limit, err) = req
|
let (limit, err) = req
|
||||||
.app_data::<JsonConfig>()
|
.app_data::<Self::Config>()
|
||||||
.map(|c| (c.limit, c.ehandler.clone()))
|
.map(|c| (c.limit, c.ehandler.clone()))
|
||||||
.unwrap_or((32768, None));
|
.unwrap_or((32768, None));
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ where
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct JsonConfig {
|
pub struct JsonConfig {
|
||||||
limit: usize,
|
limit: usize,
|
||||||
ehandler: Option<Rc<Fn(JsonPayloadError, &HttpRequest) -> Error>>,
|
ehandler: Option<Arc<dyn Fn(JsonPayloadError, &HttpRequest) -> Error + Send + Sync>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JsonConfig {
|
impl JsonConfig {
|
||||||
@ -249,9 +249,9 @@ impl JsonConfig {
|
|||||||
/// Set custom error handler
|
/// Set custom error handler
|
||||||
pub fn error_handler<F>(mut self, f: F) -> Self
|
pub fn error_handler<F>(mut self, f: F) -> Self
|
||||||
where
|
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
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user