This commit is contained in:
Ali MJ Al-Nasrawy 2021-06-18 19:06:24 +03:00
parent 532f7b9923
commit a8b55c328e
2 changed files with 10 additions and 10 deletions

View File

@ -90,7 +90,7 @@ where
.into_iter() .into_iter()
.map(|(mut rdef, srv, guards, nested)| { .map(|(mut rdef, srv, guards, nested)| {
rmap.add(&mut rdef, nested); rmap.add(&mut rdef, nested);
(rdef, srv, RefCell::new(guards)) (rdef, srv, guards.map(Rc::new))
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_boxed_slice() .into_boxed_slice()
@ -228,7 +228,7 @@ where
} }
pub struct AppRoutingFactory { pub struct AppRoutingFactory {
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>, services: Rc<[(ResourceDef, HttpNewService, Option<Rc<Guards>>)]>,
default: Rc<HttpNewService>, default: Rc<HttpNewService>,
} }
@ -244,7 +244,7 @@ impl ServiceFactory<ServiceRequest> for AppRoutingFactory {
// construct all services factory future with it's resource def and guards. // construct all services factory future with it's resource def and guards.
let factory_fut = join_all(self.services.iter().map(|(path, factory, guards)| { let factory_fut = join_all(self.services.iter().map(|(path, factory, guards)| {
let path = path.clone(); let path = path.clone();
let guards = guards.borrow_mut().take(); let guards = guards.clone();
let factory_fut = factory.new_service(()); let factory_fut = factory.new_service(());
async move { async move {
let service = factory_fut.await?; let service = factory_fut.await?;
@ -276,7 +276,7 @@ impl ServiceFactory<ServiceRequest> for AppRoutingFactory {
} }
pub struct AppRouting { pub struct AppRouting {
router: Router<HttpService, Guards>, router: Router<HttpService, Rc<Guards>>,
default: HttpService, default: HttpService,
} }
@ -290,7 +290,7 @@ impl Service<ServiceRequest> for AppRouting {
fn call(&self, mut req: ServiceRequest) -> Self::Future { fn call(&self, mut req: ServiceRequest) -> Self::Future {
let res = self.router.recognize_checked(&mut req, |req, guards| { let res = self.router.recognize_checked(&mut req, |req, guards| {
if let Some(ref guards) = guards { if let Some(ref guards) = guards {
for f in guards { for f in guards.iter() {
if !f.check(req.head()) { if !f.check(req.head()) {
return false; return false;
} }

View File

@ -432,7 +432,7 @@ where
.into_iter() .into_iter()
.map(|(mut rdef, srv, guards, nested)| { .map(|(mut rdef, srv, guards, nested)| {
rmap.add(&mut rdef, nested); rmap.add(&mut rdef, nested);
(rdef, srv, RefCell::new(guards)) (rdef, srv, guards.map(Rc::new))
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into_boxed_slice() .into_boxed_slice()
@ -458,7 +458,7 @@ where
pub struct ScopeFactory { pub struct ScopeFactory {
app_data: Option<Rc<Extensions>>, app_data: Option<Rc<Extensions>>,
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>, services: Rc<[(ResourceDef, HttpNewService, Option<Rc<Guards>>)]>,
default: Rc<HttpNewService>, default: Rc<HttpNewService>,
} }
@ -477,7 +477,7 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
// construct all services factory future with it's resource def and guards. // construct all services factory future with it's resource def and guards.
let factory_fut = join_all(self.services.iter().map(|(path, factory, guards)| { let factory_fut = join_all(self.services.iter().map(|(path, factory, guards)| {
let path = path.clone(); let path = path.clone();
let guards = guards.borrow_mut().take(); let guards = guards.clone();
let factory_fut = factory.new_service(()); let factory_fut = factory.new_service(());
async move { async move {
let service = factory_fut.await?; let service = factory_fut.await?;
@ -513,7 +513,7 @@ impl ServiceFactory<ServiceRequest> for ScopeFactory {
pub struct ScopeService { pub struct ScopeService {
app_data: Option<Rc<Extensions>>, app_data: Option<Rc<Extensions>>,
router: Router<HttpService, Vec<Box<dyn Guard>>>, router: Router<HttpService, Rc<Guards>>,
default: HttpService, default: HttpService,
} }
@ -527,7 +527,7 @@ impl Service<ServiceRequest> for ScopeService {
fn call(&self, mut req: ServiceRequest) -> Self::Future { fn call(&self, mut req: ServiceRequest) -> Self::Future {
let res = self.router.recognize_checked(&mut req, |req, guards| { let res = self.router.recognize_checked(&mut req, |req, guards| {
if let Some(ref guards) = guards { if let Some(ref guards) = guards {
for f in guards { for f in guards.iter() {
if !f.check(req.head()) { if !f.check(req.head()) {
return false; return false;
} }