1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-01 08:45:10 +02:00

refactor FromRequest trait

This commit is contained in:
Nikolay Kim
2019-04-07 14:43:07 -07:00
parent 3c650ca194
commit 75b213a6f0
18 changed files with 298 additions and 352 deletions

View File

@ -5,8 +5,9 @@ use actix_http::error::{Error, ErrorInternalServerError};
use actix_http::Extensions;
use futures::{Async, Future, IntoFuture, Poll};
use crate::dev::Payload;
use crate::extract::FromRequest;
use crate::service::ServiceFromRequest;
use crate::request::HttpRequest;
/// Application data factory
pub(crate) trait DataFactory {
@ -91,8 +92,8 @@ impl<T: 'static, P> FromRequest<P> for Data<T> {
type Future = Result<Self, Error>;
#[inline]
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
if let Some(st) = req.request().config().extensions().get::<Data<T>>() {
fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future {
if let Some(st) = req.app_config().extensions().get::<Data<T>>() {
Ok(st.clone())
} else {
Err(ErrorInternalServerError(
@ -230,7 +231,7 @@ impl<T: 'static, P> FromRequest<P> for RouteData<T> {
type Future = Result<Self, Error>;
#[inline]
fn from_request(req: &mut ServiceFromRequest<P>) -> Self::Future {
fn from_request(req: &HttpRequest, _: &mut Payload<P>) -> Self::Future {
if let Some(st) = req.route_data::<T>() {
Ok(st.clone())
} else {