diff --git a/src/config.rs b/src/config.rs index 843133034..8de43f36c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,6 @@ use crate::service::{ HttpServiceFactory, ServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse, }; -use core::borrow::{Borrow, BorrowMut}; type Guards = Vec>; type HttpNewService = @@ -240,58 +239,6 @@ impl ServiceConfig { } } -pub struct ScopeConfig { - pub(crate) services: Vec>, - pub(crate) guards: Vec>, - pub(crate) data: Option, -} - -impl ScopeConfig { - pub(crate) fn new() -> Self { - Self { - services: Vec::new(), - guards: Vec::new(), - data: Some(Extensions::new()), - } - } - - /// Set application data. Application data could be accessed - /// by using `Data` extractor where `T` is data type. - /// - /// This is same as `App::data()` method. - pub fn data(&mut self, data: S) -> &mut Self { - if self.data.is_none() { - self.data = Some(Extensions::new()); - } - - self.data.as_mut().unwrap().insert(data); - self - } - - /// Configure route for a specific path. - /// - /// This is same as `App::route()` method. - pub fn route(&mut self, path: &str, mut route: Route) -> &mut Self { - self.service( - Resource::new(path) - .add_guards(route.take_guards()) - .route(route), - ) - } - - /// Register http service. - /// - /// This is same as `App::service()` method. - pub fn service(&mut self, factory: F) -> &mut Self - where - F: HttpServiceFactory + 'static, - { - self.services - .push(Box::new(ServiceFactoryWrapper::new(factory))); - self - } -} - #[cfg(test)] mod tests { use actix_service::Service; diff --git a/src/scope.rs b/src/scope.rs index b7701b7b0..ba81312b1 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -21,7 +21,7 @@ use crate::route::Route; use crate::service::{ ServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse, }; -use crate::config::ScopeConfig; +use crate::config::ServiceConfig; type Guards = Vec>; type HttpService = BoxedService; @@ -117,25 +117,22 @@ impl Scope { /// ``` pub fn configure(mut self, f: F) -> Self where - F: FnOnce(&mut ScopeConfig), + F: FnOnce(&mut ServiceConfig), { - let mut cfg = ScopeConfig::new(); + let mut cfg = ServiceConfig::new(); f(&mut cfg); self.services.extend(cfg.services); - self.guards.extend(cfg.guards); - //self.data.extend(cfg.data); - if cfg.data.is_some() { + if !cfg.data.is_empty() { if (&self).data.is_some() { - let mut new_data = Extensions::from(cfg.data.unwrap()); + let mut data = self.data.unwrap(); - let old_data = Extensions::from(self.data.take().unwrap()); - for value in old_data.into_iter() { - new_data.insert(value); + for value in cfg.data.iter() { + value.create(&mut data); } - self.data = Some(new_data); + self.data = Some(data); } } self diff --git a/src/web.rs b/src/web.rs index 4a83d601e..5669a1e86 100644 --- a/src/web.rs +++ b/src/web.rs @@ -14,7 +14,6 @@ use crate::route::Route; use crate::scope::Scope; use crate::service::WebService; -pub use crate::config::ScopeConfig; pub use crate::config::ServiceConfig; pub use crate::data::Data; pub use crate::request::HttpRequest;