This commit is contained in:
Rhys 2018-04-07 05:13:37 +00:00 committed by GitHub
commit 4bb0f54068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

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