mirror of https://github.com/fafhrd91/actix-web
relocate FnDataFactory
This commit is contained in:
parent
ce24630d31
commit
c367a77dcd
|
@ -67,6 +67,10 @@ impl fmt::Debug for Extensions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_remove() {
|
fn test_remove() {
|
||||||
let mut map = Extensions::new();
|
let mut map = Extensions::new();
|
||||||
|
@ -172,3 +176,4 @@ fn test_extensions() {
|
||||||
assert_eq!(extensions.get::<bool>(), None);
|
assert_eq!(extensions.get::<bool>(), None);
|
||||||
assert_eq!(extensions.get(), Some(&MyType(10)));
|
assert_eq!(extensions.get(), Some(&MyType(10)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@ use actix_service::boxed::{self, BoxServiceFactory};
|
||||||
use actix_service::{
|
use actix_service::{
|
||||||
apply, apply_fn_factory, IntoServiceFactory, ServiceFactory, Transform,
|
apply, apply_fn_factory, IntoServiceFactory, ServiceFactory, Transform,
|
||||||
};
|
};
|
||||||
use futures::future::{FutureExt, LocalBoxFuture};
|
use futures::future::FutureExt;
|
||||||
|
|
||||||
use crate::app_service::{AppEntry, AppInit, AppRoutingFactory};
|
use crate::app_service::{AppEntry, AppInit, AppRoutingFactory};
|
||||||
use crate::config::ServiceConfig;
|
use crate::config::ServiceConfig;
|
||||||
use crate::data::{Data, DataFactory};
|
use crate::data::{Data, DataFactory, FnDataFactory};
|
||||||
use crate::dev::ResourceDef;
|
use crate::dev::ResourceDef;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::resource::Resource;
|
use crate::resource::Resource;
|
||||||
|
@ -25,8 +25,6 @@ use crate::service::{
|
||||||
};
|
};
|
||||||
|
|
||||||
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||||
type FnDataFactory =
|
|
||||||
Box<dyn Fn() -> LocalBoxFuture<'static, Result<Box<dyn DataFactory>, ()>>>;
|
|
||||||
|
|
||||||
/// Application builder - structure that follows the builder pattern
|
/// Application builder - structure that follows the builder pattern
|
||||||
/// for building application instances.
|
/// for building application instances.
|
||||||
|
|
|
@ -12,7 +12,7 @@ use actix_service::{fn_service, Service, ServiceFactory};
|
||||||
use futures::future::{ok, FutureExt, LocalBoxFuture};
|
use futures::future::{ok, FutureExt, LocalBoxFuture};
|
||||||
|
|
||||||
use crate::config::{AppConfig, AppService};
|
use crate::config::{AppConfig, AppService};
|
||||||
use crate::data::DataFactory;
|
use crate::data::{FnDataFactory, DataFactory};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::guard::Guard;
|
use crate::guard::Guard;
|
||||||
use crate::request::{HttpRequest, HttpRequestPool};
|
use crate::request::{HttpRequest, HttpRequestPool};
|
||||||
|
@ -23,8 +23,6 @@ type Guards = Vec<Box<dyn Guard>>;
|
||||||
type HttpService = BoxService<ServiceRequest, ServiceResponse, Error>;
|
type HttpService = BoxService<ServiceRequest, ServiceResponse, Error>;
|
||||||
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||||
type BoxResponse = LocalBoxFuture<'static, Result<ServiceResponse, Error>>;
|
type BoxResponse = LocalBoxFuture<'static, Result<ServiceResponse, Error>>;
|
||||||
type FnDataFactory =
|
|
||||||
Box<dyn Fn() -> LocalBoxFuture<'static, Result<Box<dyn DataFactory>, ()>>>;
|
|
||||||
|
|
||||||
/// Service factory to convert `Request` to a `ServiceRequest<S>`.
|
/// Service factory to convert `Request` to a `ServiceRequest<S>`.
|
||||||
/// It also executes data factories.
|
/// It also executes data factories.
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use actix_http::error::{Error, ErrorInternalServerError};
|
use actix_http::error::{Error, ErrorInternalServerError};
|
||||||
use actix_http::Extensions;
|
use actix_http::Extensions;
|
||||||
use futures::future::{err, ok, Ready};
|
use futures::future::{err, ok, LocalBoxFuture, Ready};
|
||||||
|
|
||||||
use crate::dev::Payload;
|
use crate::dev::Payload;
|
||||||
use crate::extract::FromRequest;
|
use crate::extract::FromRequest;
|
||||||
|
@ -14,6 +14,9 @@ pub(crate) trait DataFactory {
|
||||||
fn create(&self, extensions: &mut Extensions) -> bool;
|
fn create(&self, extensions: &mut Extensions) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) type FnDataFactory =
|
||||||
|
Box<dyn Fn() -> LocalBoxFuture<'static, Result<Box<dyn DataFactory>, ()>>>;
|
||||||
|
|
||||||
/// Application data.
|
/// Application data.
|
||||||
///
|
///
|
||||||
/// Application data is an arbitrary data attached to the app.
|
/// Application data is an arbitrary data attached to the app.
|
||||||
|
|
Loading…
Reference in New Issue