1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 08:57:00 +02:00

add resource map, it allow to check if router has resource and it allows to generate urls for named resources

This commit is contained in:
Nikolay Kim
2019-03-09 07:39:34 -08:00
parent 2f6df11183
commit aadcdaa3d6
13 changed files with 361 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ use actix_router::ResourceDef;
use actix_service::{boxed, IntoNewService, NewService};
use crate::guard::Guard;
use crate::rmap::ResourceMap;
use crate::service::{ServiceRequest, ServiceResponse};
type Guards = Vec<Box<Guard>>;
@@ -18,7 +19,12 @@ pub struct AppConfig<P> {
host: String,
root: bool,
default: Rc<HttpNewService<P>>,
services: Vec<(ResourceDef, HttpNewService<P>, Option<Guards>)>,
services: Vec<(
ResourceDef,
HttpNewService<P>,
Option<Guards>,
Option<Rc<ResourceMap>>,
)>,
}
impl<P: 'static> AppConfig<P> {
@@ -46,7 +52,12 @@ impl<P: 'static> AppConfig<P> {
pub(crate) fn into_services(
self,
) -> Vec<(ResourceDef, HttpNewService<P>, Option<Guards>)> {
) -> Vec<(
ResourceDef,
HttpNewService<P>,
Option<Guards>,
Option<Rc<ResourceMap>>,
)> {
self.services
}
@@ -85,6 +96,7 @@ impl<P: 'static> AppConfig<P> {
rdef: ResourceDef,
guards: Option<Vec<Box<Guard>>>,
service: F,
nested: Option<Rc<ResourceMap>>,
) where
F: IntoNewService<S, ServiceRequest<P>>,
S: NewService<
@@ -98,6 +110,7 @@ impl<P: 'static> AppConfig<P> {
rdef,
boxed::new_service(service.into_new_service()),
guards,
nested,
));
}
}