From 24d12289435db12517741e818a23cb811cc5301b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 3 Sep 2018 11:28:47 -0700 Subject: [PATCH] simplify handler path processing --- src/application.rs | 7 ++----- src/scope.rs | 9 +-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/application.rs b/src/application.rs index 3ef753f5f..407268322 100644 --- a/src/application.rs +++ b/src/application.rs @@ -447,11 +447,8 @@ where { let mut path = path.trim().trim_right_matches('/').to_owned(); if !path.is_empty() && !path.starts_with('/') { - path.insert(0, '/') - } - if path.len() > 1 && path.ends_with('/') { - path.pop(); - } + path.insert(0, '/'); + }; self.parts .as_mut() .expect("Use after finish") diff --git a/src/scope.rs b/src/scope.rs index 6e7f28985..4ce4901af 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -313,14 +313,7 @@ impl Scope { /// } /// ``` pub fn handler>(mut self, path: &str, handler: H) -> Scope { - let mut path = path.trim().trim_right_matches('/').to_owned(); - if !path.is_empty() && !path.starts_with('/') { - path.insert(0, '/') - } - if path.len() > 1 && path.ends_with('/') { - path.pop(); - } - + let path = insert_slash(path.trim().trim_right_matches('/')); Rc::get_mut(&mut self.router) .expect("Multiple copies of scope router") .register_handler(&path, Box::new(WrapHandler::new(handler)), None);