mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 05:52:59 +01:00
allow register router resource for ResourceDef
This commit is contained in:
parent
9979bfb3ef
commit
a53f06a1a4
@ -89,7 +89,6 @@ where
|
|||||||
/// `ApplyNewService` new service combinator
|
/// `ApplyNewService` new service combinator
|
||||||
pub struct ApplyNewService<T, S>
|
pub struct ApplyNewService<T, S>
|
||||||
where
|
where
|
||||||
// T::InitError: From<S::InitError>,
|
|
||||||
T: NewTransform<S::Service, InitError = S::InitError>,
|
T: NewTransform<S::Service, InitError = S::InitError>,
|
||||||
T::Error: From<S::Error>,
|
T::Error: From<S::Error>,
|
||||||
S: NewService,
|
S: NewService,
|
||||||
|
@ -115,16 +115,25 @@ pub struct RouterBuilder<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> RouterBuilder<T> {
|
impl<T> RouterBuilder<T> {
|
||||||
|
/// Register resource for specified path.
|
||||||
pub fn path(&mut self, path: &str, resource: T) {
|
pub fn path(&mut self, path: &str, resource: T) {
|
||||||
self.rmap.register(ResourceDef::new(path));
|
self.rmap.register(ResourceDef::new(path));
|
||||||
self.resources.push(resource);
|
self.resources.push(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register resource for specified path prefix.
|
||||||
pub fn prefix(&mut self, prefix: &str, resource: T) {
|
pub fn prefix(&mut self, prefix: &str, resource: T) {
|
||||||
self.rmap.register(ResourceDef::prefix(prefix));
|
self.rmap.register(ResourceDef::prefix(prefix));
|
||||||
self.resources.push(resource);
|
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> {
|
pub fn finish(self) -> Router<T> {
|
||||||
Router {
|
Router {
|
||||||
rmap: Rc::new(self.rmap),
|
rmap: Rc::new(self.rmap),
|
||||||
|
Loading…
Reference in New Issue
Block a user