1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-01-05 14:58:44 +00:00

Added support for configuring a named resource

This commit is contained in:
lyptt 2018-04-02 09:12:27 +01:00
parent 74d0656d27
commit 8232045f53

View file

@ -251,6 +251,23 @@ impl<S> App<S> where S: 'static {
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.
pub fn default_resource<F>(mut self, f: F) -> App<S>
where F: FnOnce(&mut ResourceHandler<S>) + 'static