1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 21:51:06 +01:00

allow register router resource for ResourceDef

This commit is contained in:
Nikolay Kim 2019-02-09 20:43:39 -08:00
parent 9979bfb3ef
commit a53f06a1a4
2 changed files with 9 additions and 1 deletions

View File

@ -89,7 +89,6 @@ where
/// `ApplyNewService` new service combinator
pub struct ApplyNewService<T, S>
where
// T::InitError: From<S::InitError>,
T: NewTransform<S::Service, InitError = S::InitError>,
T::Error: From<S::Error>,
S: NewService,

View File

@ -115,16 +115,25 @@ pub struct RouterBuilder<T> {
}
impl<T> RouterBuilder<T> {
/// Register resource for specified path.
pub fn path(&mut self, path: &str, resource: T) {
self.rmap.register(ResourceDef::new(path));
self.resources.push(resource);
}
/// Register resource for specified path prefix.
pub fn prefix(&mut self, prefix: &str, resource: T) {
self.rmap.register(ResourceDef::prefix(prefix));
self.resources.push(resource);
}
/// Register resource for ResourceDef
pub fn rdef(&mut self, rdef: ResourceDef, resource: T) {
self.rmap.register(rdef);
self.resources.push(resource);
}
/// Finish configuration and create router instance.
pub fn finish(self) -> Router<T> {
Router {
rmap: Rc::new(self.rmap),