mirror of
https://github.com/actix/actix-web.git
synced 2025-01-21 14:38:07 +00:00
Added support for configuring a named resource
This commit is contained in:
parent
74d0656d27
commit
8232045f53
1 changed files with 17 additions and 0 deletions
|
@ -251,6 +251,23 @@ impl<S> App<S> where S: 'static {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn named_resource<F>(mut self, name: &str, path: &str, f: F) -> App<S>
|
||||||
|
where F: FnOnce(&mut ResourceHandler<S>) + 'static
|
||||||
|
{
|
||||||
|
{
|
||||||
|
let parts = self.parts.as_mut().expect("Use after finish");
|
||||||
|
|
||||||
|
// add resource
|
||||||
|
let mut resource = ResourceHandler::default();
|
||||||
|
resource.name(name);
|
||||||
|
f(&mut resource);
|
||||||
|
|
||||||
|
let pattern = Resource::new(resource.get_name(), path);
|
||||||
|
parts.resources.push((pattern, Some(resource)));
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Default resource is used if no matched route could be found.
|
/// Default resource is used if no matched route could be found.
|
||||||
pub fn default_resource<F>(mut self, f: F) -> App<S>
|
pub fn default_resource<F>(mut self, f: F) -> App<S>
|
||||||
where F: FnOnce(&mut ResourceHandler<S>) + 'static
|
where F: FnOnce(&mut ResourceHandler<S>) + 'static
|
||||||
|
|
Loading…
Reference in a new issue