From 01bf3b7b5fb708af516fee52eb6ad197c8ce5d97 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 7 May 2019 11:08:30 +0200 Subject: [PATCH] move find_method to Router class --- src/api_schema/config.rs | 11 +---------- src/api_schema/router.rs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/api_schema/config.rs b/src/api_schema/config.rs index e8ac4a4c..77bc528c 100644 --- a/src/api_schema/config.rs +++ b/src/api_schema/config.rs @@ -25,16 +25,7 @@ impl ApiConfig { pub fn find_method(&self, components: &[&str], method: Method, uri_param: &mut HashMap) -> &'static MethodDefinition { - if let Some(info) = self.router.find_route(components, uri_param) { - return match method { - Method::GET => &info.get, - Method::PUT => &info.put, - Method::POST => &info.post, - Method::DELETE => &info.delete, - _ => &MethodDefinition::None, - }; - } - &MethodDefinition::None + self.router.find_method(components, method, uri_param) } pub fn find_alias(&self, components: &[&str]) -> PathBuf { diff --git a/src/api_schema/router.rs b/src/api_schema/router.rs index 834b46d9..a2605e19 100644 --- a/src/api_schema/router.rs +++ b/src/api_schema/router.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::sync::Arc; use std::fmt; -use hyper::{Body, Response, StatusCode}; +use hyper::{Body, Method, Response, StatusCode}; use hyper::rt::Future; use hyper::http::request::Parts; @@ -305,4 +305,23 @@ impl Router { None } + + pub fn find_method( + &self, + components: &[&str], + method: Method, + uri_param: &mut HashMap + ) -> &MethodDefinition { + + if let Some(info) = self.find_route(components, uri_param) { + return match method { + Method::GET => &info.get, + Method::PUT => &info.put, + Method::POST => &info.post, + Method::DELETE => &info.delete, + _ => &MethodDefinition::None, + }; + } + &MethodDefinition::None + } }