From b8b90d9ec9ab449ad2f967604ec8b8a27e646bff Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 12 Jul 2018 15:30:01 +0600 Subject: [PATCH] rename ResourceHandler to Resource --- src/application.rs | 38 +++++++------- src/extractor.rs | 16 +++--- src/handler.rs | 4 +- src/httprequest.rs | 35 +++++++------ src/lib.rs | 4 +- src/middleware/cors.rs | 14 +++--- src/resource.rs | 12 ++--- src/router.rs | 110 ++++++++++++++++++++--------------------- src/scope.rs | 32 ++++++------ src/test.rs | 4 +- 10 files changed, 137 insertions(+), 132 deletions(-) diff --git a/src/application.rs b/src/application.rs index de474dfcf..96c4ad11f 100644 --- a/src/application.rs +++ b/src/application.rs @@ -9,8 +9,8 @@ use httpresponse::HttpResponse; use middleware::Middleware; use pipeline::{HandlerType, Pipeline, PipelineHandler}; use pred::Predicate; -use resource::ResourceHandler; -use router::{Resource, RouteInfo, Router}; +use resource::Resource; +use router::{ResourceDef, RouteInfo, Router}; use scope::Scope; use server::{HttpHandler, HttpHandlerTask, IntoHttpHandler, Request}; @@ -28,15 +28,15 @@ pub struct HttpApplication { #[doc(hidden)] pub struct Inner { prefix: usize, - default: Rc>, + default: Rc>, encoding: ContentEncoding, - resources: Vec>, + resources: Vec>, handlers: Vec>, } enum PrefixHandlerType { Handler(String, Box>), - Scope(Resource, Box>, Vec>>), + Scope(ResourceDef, Box>, Vec>>), } impl PipelineHandler for Inner { @@ -154,10 +154,10 @@ impl HttpHandler for HttpApplication { struct ApplicationParts { state: S, prefix: String, - default: Rc>, - resources: Vec<(Resource, Option>)>, + default: Rc>, + resources: Vec<(ResourceDef, Option>)>, handlers: Vec>, - external: HashMap, + external: HashMap, encoding: ContentEncoding, middlewares: Vec>>, filters: Vec>>, @@ -204,7 +204,7 @@ where parts: Some(ApplicationParts { state, prefix: "/".to_owned(), - default: Rc::new(ResourceHandler::default_not_found()), + default: Rc::new(Resource::default_not_found()), resources: Vec::new(), handlers: Vec::new(), external: HashMap::new(), @@ -332,9 +332,9 @@ where } } } else { - let mut handler = ResourceHandler::default(); + let mut handler = Resource::default(); handler.method(method).with(f); - let pattern = Resource::new(handler.get_name(), path); + let pattern = ResourceDef::new(handler.get_name(), path); break Some((pattern, Some(handler))); } } @@ -382,7 +382,7 @@ where let filters = scope.take_filters(); parts.handlers.push(PrefixHandlerType::Scope( - Resource::prefix("", &path), + ResourceDef::prefix("", &path), scope, filters, )); @@ -423,16 +423,16 @@ where /// ``` pub fn resource(mut self, path: &str, f: F) -> App where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { { let parts = self.parts.as_mut().expect("Use after finish"); // add resource handler - let mut handler = ResourceHandler::default(); + let mut handler = Resource::default(); f(&mut handler); - let pattern = Resource::new(handler.get_name(), path); + let pattern = ResourceDef::new(handler.get_name(), path); parts.resources.push((pattern, Some(handler))); } self @@ -440,8 +440,8 @@ where /// Configure resource for a specific path. #[doc(hidden)] - pub fn register_resource(&mut self, path: &str, resource: ResourceHandler) { - let pattern = Resource::new(resource.get_name(), path); + pub fn register_resource(&mut self, path: &str, resource: Resource) { + let pattern = ResourceDef::new(resource.get_name(), path); self.parts .as_mut() .expect("Use after finish") @@ -452,7 +452,7 @@ where /// Default resource to be used if no matching route could be found. pub fn default_resource(mut self, f: F) -> App where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { { let parts = self.parts.as_mut().expect("Use after finish"); @@ -508,7 +508,7 @@ where } parts.external.insert( String::from(name.as_ref()), - Resource::external(name.as_ref(), url.as_ref()), + ResourceDef::external(name.as_ref(), url.as_ref()), ); } self diff --git a/src/extractor.rs b/src/extractor.rs index 8e0a96594..683e1526d 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -613,8 +613,8 @@ mod tests { use futures::{Async, Future}; use http::header; use mime; - use resource::ResourceHandler; - use router::{Resource, Router}; + use resource::Resource; + use router::{ResourceDef, Router}; use test::TestRequest; #[derive(Deserialize, Debug, PartialEq)] @@ -710,10 +710,10 @@ mod tests { fn test_request_extract() { let req = TestRequest::with_uri("/name/user1/?id=test").finish(); - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); let mut routes = Vec::new(); - routes.push((Resource::new("index", "/{key}/{value}/"), Some(resource))); + routes.push((ResourceDef::new("index", "/{key}/{value}/"), Some(resource))); let (router, _) = Router::new("", routes); let info = router.recognize(&req).unwrap().1; let req = req.with_route_info(info); @@ -748,10 +748,10 @@ mod tests { #[test] fn test_extract_path_single() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); let mut routes = Vec::new(); - routes.push((Resource::new("index", "/{value}/"), Some(resource))); + routes.push((ResourceDef::new("index", "/{value}/"), Some(resource))); let (router, _) = Router::new("", routes); let req = TestRequest::with_uri("/32/").finish_with_router(router.clone()); @@ -762,10 +762,10 @@ mod tests { #[test] fn test_tuple_extract() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); let mut routes = Vec::new(); - routes.push((Resource::new("index", "/{key}/{value}/"), Some(resource))); + routes.push((ResourceDef::new("index", "/{key}/{value}/"), Some(resource))); let (router, _) = Router::new("", routes); let req = TestRequest::with_uri("/name/user1/?id=test") diff --git a/src/handler.rs b/src/handler.rs index 690d71664..241f4e6a6 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -9,7 +9,7 @@ use error::Error; use http::StatusCode; use httprequest::HttpRequest; use httpresponse::HttpResponse; -use resource::ResourceHandler; +use resource::Resource; /// Trait defines object that could be registered as route handler #[allow(unused_variables)] @@ -409,7 +409,7 @@ pub(crate) trait RouteHandler: 'static { false } - fn default_resource(&mut self, _: Rc>) { + fn default_resource(&mut self, _: Rc>) { unimplemented!() } } diff --git a/src/httprequest.rs b/src/httprequest.rs index 08de0a8fe..650d3a39c 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -20,7 +20,7 @@ use httpresponse::{HttpResponse, HttpResponseBuilder}; use info::ConnectionInfo; use param::Params; use payload::Payload; -use router::{Resource, RouteInfo}; +use router::{ResourceDef, RouteInfo}; use server::Request; struct Query(HashMap); @@ -211,7 +211,7 @@ impl HttpRequest { /// This method returns reference to matched `Resource` object. #[inline] - pub fn resource(&self) -> Option<&Resource> { + pub fn resource(&self) -> Option<&ResourceDef> { self.route.resource() } @@ -370,8 +370,8 @@ impl fmt::Debug for HttpRequest { #[cfg(test)] mod tests { use super::*; - use resource::ResourceHandler; - use router::{Resource, Router}; + use resource::Resource; + use router::{ResourceDef, Router}; use test::TestRequest; #[test] @@ -422,10 +422,10 @@ mod tests { #[test] fn test_request_match_info() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); let mut routes = Vec::new(); - routes.push((Resource::new("index", "/{key}/"), Some(resource))); + routes.push((ResourceDef::new("index", "/{key}/"), Some(resource))); let (router, _) = Router::new("", routes); let req = TestRequest::with_uri("/value/?id=test").finish(); @@ -435,10 +435,12 @@ mod tests { #[test] fn test_url_for() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); - let routes = - vec![(Resource::new("index", "/user/{name}.{ext}"), Some(resource))]; + let routes = vec![( + ResourceDef::new("index", "/user/{name}.{ext}"), + Some(resource), + )]; let (router, _) = Router::new("/", routes); let info = router.default_route_info(); assert!(info.has_route("/user/test.html")); @@ -464,9 +466,12 @@ mod tests { #[test] fn test_url_for_with_prefix() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); - let routes = vec![(Resource::new("index", "/user/{name}.html"), Some(resource))]; + let routes = vec![( + ResourceDef::new("index", "/user/{name}.html"), + Some(resource), + )]; let (router, _) = Router::new("/prefix/", routes); let info = router.default_route_info(); assert!(info.has_route("/user/test.html")); @@ -483,9 +488,9 @@ mod tests { #[test] fn test_url_for_static() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); - let routes = vec![(Resource::new("index", "/index.html"), Some(resource))]; + let routes = vec![(ResourceDef::new("index", "/index.html"), Some(resource))]; let (router, _) = Router::new("/prefix/", routes); let info = router.default_route_info(); assert!(info.has_route("/index.html")); @@ -503,10 +508,10 @@ mod tests { #[test] fn test_url_for_external() { - let mut resource = ResourceHandler::<()>::default(); + let mut resource = Resource::<()>::default(); resource.name("index"); let routes = vec![( - Resource::external("youtube", "https://youtube.com/watch/{video_id}"), + ResourceDef::external("youtube", "https://youtube.com/watch/{video_id}"), None, )]; let router = Router::new::<()>("", routes).0; diff --git a/src/lib.rs b/src/lib.rs index a301227b3..a1a09982a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -244,9 +244,9 @@ pub mod dev { pub use info::ConnectionInfo; pub use json::{JsonBody, JsonConfig}; pub use param::{FromParam, Params}; - pub use resource::ResourceHandler; + pub use resource::Resource; pub use route::Route; - pub use router::{Resource, ResourceType, Router}; + pub use router::{ResourceDef, ResourceType, Router}; } pub mod http { diff --git a/src/middleware/cors.rs b/src/middleware/cors.rs index 09ca81205..3f0f7ef5f 100644 --- a/src/middleware/cors.rs +++ b/src/middleware/cors.rs @@ -11,7 +11,7 @@ //! constructed backend. //! //! Cors middleware could be used as parameter for `App::middleware()` or -//! `ResourceHandler::middleware()` methods. But you have to use +//! `Resource::middleware()` methods. But you have to use //! `Cors::for_app()` method to support *preflight* OPTIONS request. //! //! @@ -59,7 +59,7 @@ use httpmessage::HttpMessage; use httprequest::HttpRequest; use httpresponse::HttpResponse; use middleware::{Middleware, Response, Started}; -use resource::ResourceHandler; +use resource::Resource; use server::Request; /// A set of errors that can occur during processing CORS @@ -277,9 +277,9 @@ impl Cors { /// adds route for *OPTIONS* preflight requests. /// /// It is possible to register *Cors* middleware with - /// `ResourceHandler::middleware()` method, but in that case *Cors* + /// `Resource::middleware()` method, but in that case *Cors* /// middleware wont be able to handle *OPTIONS* requests. - pub fn register(self, resource: &mut ResourceHandler) { + pub fn register(self, resource: &mut Resource) { resource .method(Method::OPTIONS) .h(|_: &_| HttpResponse::Ok()); @@ -515,7 +515,7 @@ pub struct CorsBuilder { methods: bool, error: Option, expose_hdrs: HashSet, - resources: Vec<(String, ResourceHandler)>, + resources: Vec<(String, Resource)>, app: Option>, } @@ -795,10 +795,10 @@ impl CorsBuilder { /// ``` pub fn resource(&mut self, path: &str, f: F) -> &mut CorsBuilder where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { // add resource handler - let mut handler = ResourceHandler::default(); + let mut handler = Resource::default(); f(&mut handler); self.resources.push((path.to_owned(), handler)); diff --git a/src/resource.rs b/src/resource.rs index cbf3d9858..2af1029ad 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -36,16 +36,16 @@ pub(crate) struct RouteId(usize); /// "/", |r| r.method(http::Method::GET).f(|r| HttpResponse::Ok())) /// .finish(); /// } -pub struct ResourceHandler { +pub struct Resource { name: String, state: PhantomData, routes: SmallVec<[Route; 3]>, middlewares: Rc>>>, } -impl Default for ResourceHandler { +impl Default for Resource { fn default() -> Self { - ResourceHandler { + Resource { name: String::new(), state: PhantomData, routes: SmallVec::new(), @@ -54,9 +54,9 @@ impl Default for ResourceHandler { } } -impl ResourceHandler { +impl Resource { pub(crate) fn default_not_found() -> Self { - ResourceHandler { + Resource { name: String::new(), state: PhantomData, routes: SmallVec::new(), @@ -74,7 +74,7 @@ impl ResourceHandler { } } -impl ResourceHandler { +impl Resource { /// Register a new route and return mutable reference to *Route* object. /// *Route* is used for route configuration, i.e. adding predicates, /// setting up handler. diff --git a/src/router.rs b/src/router.rs index 0edf51844..fad51b15e 100644 --- a/src/router.rs +++ b/src/router.rs @@ -7,7 +7,7 @@ use url::Url; use error::UrlGenerationError; use param::{ParamItem, Params}; -use resource::ResourceHandler; +use resource::Resource; use server::Request; #[derive(Debug, Copy, Clone, PartialEq)] @@ -29,7 +29,7 @@ pub struct RouteInfo { impl RouteInfo { /// This method returns reference to matched `Resource` object. #[inline] - pub fn resource(&self) -> Option<&Resource> { + pub fn resource(&self) -> Option<&ResourceDef> { if let RouterResource::Normal(idx) = self.resource { Some(&self.router.patterns[idx as usize]) } else { @@ -113,15 +113,15 @@ impl RouteInfo { struct Inner { prefix: String, prefix_len: usize, - named: HashMap, - patterns: Vec, + named: HashMap, + patterns: Vec, } impl Router { /// Create new router pub fn new( - prefix: &str, map: Vec<(Resource, Option>)>, - ) -> (Router, Vec>) { + prefix: &str, map: Vec<(ResourceDef, Option>)>, + ) -> (Router, Vec>) { let prefix = prefix.trim().trim_right_matches('/').to_owned(); let mut named = HashMap::new(); let mut patterns = Vec::new(); @@ -240,7 +240,7 @@ pub enum ResourceType { /// Resource type describes an entry in resources table #[derive(Clone, Debug)] -pub struct Resource { +pub struct ResourceDef { tp: PatternType, rtp: ResourceType, name: String, @@ -248,12 +248,12 @@ pub struct Resource { elements: Vec, } -impl Resource { +impl ResourceDef { /// Parse path pattern and create new `Resource` instance. /// /// Panics if path pattern is wrong. pub fn new(name: &str, path: &str) -> Self { - Resource::with_prefix(name, path, "/", false) + ResourceDef::with_prefix(name, path, "/", false) } /// Parse path pattern and create new `Resource` instance. @@ -262,14 +262,14 @@ impl Resource { /// /// Panics if path regex pattern is wrong. pub fn prefix(name: &str, path: &str) -> Self { - Resource::with_prefix(name, path, "/", true) + ResourceDef::with_prefix(name, path, "/", true) } /// Construct external resource /// /// Panics if path pattern is wrong. pub fn external(name: &str, path: &str) -> Self { - let mut resource = Resource::with_prefix(name, path, "/", false); + let mut resource = ResourceDef::with_prefix(name, path, "/", false); resource.rtp = ResourceType::External; resource } @@ -277,7 +277,7 @@ impl Resource { /// Parse path pattern and create new `Resource` instance with custom prefix pub fn with_prefix(name: &str, path: &str, prefix: &str, for_prefix: bool) -> Self { let (pattern, elements, is_dynamic, len) = - Resource::parse(path, prefix, for_prefix); + ResourceDef::parse(path, prefix, for_prefix); let tp = if is_dynamic { let re = match Regex::new(&pattern) { @@ -296,7 +296,7 @@ impl Resource { PatternType::Static(pattern.clone()) }; - Resource { + ResourceDef { tp, elements, name: name.into(), @@ -571,15 +571,15 @@ impl Resource { } } -impl PartialEq for Resource { - fn eq(&self, other: &Resource) -> bool { +impl PartialEq for ResourceDef { + fn eq(&self, other: &ResourceDef) -> bool { self.pattern == other.pattern } } -impl Eq for Resource {} +impl Eq for ResourceDef {} -impl Hash for Resource { +impl Hash for ResourceDef { fn hash(&self, state: &mut H) { self.pattern.hash(state); } @@ -593,34 +593,34 @@ mod tests { #[test] fn test_recognizer10() { let routes = vec![ - (Resource::new("", "/name"), Some(ResourceHandler::default())), + (ResourceDef::new("", "/name"), Some(Resource::default())), ( - Resource::new("", "/name/{val}"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/name/{val}"), + Some(Resource::default()), ), ( - Resource::new("", "/name/{val}/index.html"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/name/{val}/index.html"), + Some(Resource::default()), ), ( - Resource::new("", "/file/{file}.{ext}"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/file/{file}.{ext}"), + Some(Resource::default()), ), ( - Resource::new("", "/v{val}/{val2}/index.html"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/v{val}/{val2}/index.html"), + Some(Resource::default()), ), ( - Resource::new("", "/v/{tail:.*}"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/v/{tail:.*}"), + Some(Resource::default()), ), ( - Resource::new("", "/test2/{test}.html"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/test2/{test}.html"), + Some(Resource::default()), ), ( - Resource::new("", "{test}/index.html"), - Some(ResourceHandler::default()), + ResourceDef::new("", "{test}/index.html"), + Some(Resource::default()), ), ]; let (rec, _) = Router::new::<()>("", routes); @@ -681,12 +681,12 @@ mod tests { fn test_recognizer_2() { let routes = vec![ ( - Resource::new("", "/index.json"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/index.json"), + Some(Resource::default()), ), ( - Resource::new("", "/{source}.json"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/{source}.json"), + Some(Resource::default()), ), ]; let (rec, _) = Router::new::<()>("", routes); @@ -701,10 +701,10 @@ mod tests { #[test] fn test_recognizer_with_prefix() { let routes = vec![ - (Resource::new("", "/name"), Some(ResourceHandler::default())), + (ResourceDef::new("", "/name"), Some(Resource::default())), ( - Resource::new("", "/name/{val}"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/name/{val}"), + Some(Resource::default()), ), ]; let (rec, _) = Router::new::<()>("/test", routes); @@ -724,10 +724,10 @@ mod tests { // same patterns let routes = vec![ - (Resource::new("", "/name"), Some(ResourceHandler::default())), + (ResourceDef::new("", "/name"), Some(Resource::default())), ( - Resource::new("", "/name/{val}"), - Some(ResourceHandler::default()), + ResourceDef::new("", "/name/{val}"), + Some(Resource::default()), ), ]; let (rec, _) = Router::new::<()>("/test2", routes); @@ -747,29 +747,29 @@ mod tests { #[test] fn test_parse_static() { - let re = Resource::new("test", "/"); + let re = ResourceDef::new("test", "/"); assert!(re.is_match("/")); assert!(!re.is_match("/a")); - let re = Resource::new("test", "/name"); + let re = ResourceDef::new("test", "/name"); assert!(re.is_match("/name")); assert!(!re.is_match("/name1")); assert!(!re.is_match("/name/")); assert!(!re.is_match("/name~")); - let re = Resource::new("test", "/name/"); + let re = ResourceDef::new("test", "/name/"); assert!(re.is_match("/name/")); assert!(!re.is_match("/name")); assert!(!re.is_match("/name/gs")); - let re = Resource::new("test", "/user/profile"); + let re = ResourceDef::new("test", "/user/profile"); assert!(re.is_match("/user/profile")); assert!(!re.is_match("/user/profile/profile")); } #[test] fn test_parse_param() { - let re = Resource::new("test", "/user/{id}"); + let re = ResourceDef::new("test", "/user/{id}"); assert!(re.is_match("/user/profile")); assert!(re.is_match("/user/2345")); assert!(!re.is_match("/user/2345/")); @@ -783,7 +783,7 @@ mod tests { let info = re.match_with_params(&req, 0, true).unwrap(); assert_eq!(info.get("id").unwrap(), "1245125"); - let re = Resource::new("test", "/v{version}/resource/{id}"); + let re = ResourceDef::new("test", "/v{version}/resource/{id}"); assert!(re.is_match("/v1/resource/320120")); assert!(!re.is_match("/v/resource/1")); assert!(!re.is_match("/resource")); @@ -796,14 +796,14 @@ mod tests { #[test] fn test_resource_prefix() { - let re = Resource::prefix("test", "/name"); + let re = ResourceDef::prefix("test", "/name"); assert!(re.is_match("/name")); assert!(re.is_match("/name/")); assert!(re.is_match("/name/test/test")); assert!(re.is_match("/name1")); assert!(re.is_match("/name~")); - let re = Resource::prefix("test", "/name/"); + let re = ResourceDef::prefix("test", "/name/"); assert!(re.is_match("/name/")); assert!(re.is_match("/name/gs")); assert!(!re.is_match("/name")); @@ -811,7 +811,7 @@ mod tests { #[test] fn test_reousrce_prefix_dynamic() { - let re = Resource::prefix("test", "/{name}/"); + let re = ResourceDef::prefix("test", "/{name}/"); assert!(re.is_match("/name/")); assert!(re.is_match("/name/gs")); assert!(!re.is_match("/name")); @@ -831,12 +831,12 @@ mod tests { fn test_request_resource() { let routes = vec![ ( - Resource::new("r1", "/index.json"), - Some(ResourceHandler::default()), + ResourceDef::new("r1", "/index.json"), + Some(Resource::default()), ), ( - Resource::new("r2", "/test.json"), - Some(ResourceHandler::default()), + ResourceDef::new("r2", "/test.json"), + Some(Resource::default()), ), ]; let (router, _) = Router::new::<()>("", routes); diff --git a/src/scope.rs b/src/scope.rs index ffa581578..a4b4307c3 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -14,14 +14,14 @@ use middleware::{ Started as MiddlewareStarted, }; use pred::Predicate; -use resource::{ResourceHandler, RouteId}; -use router::Resource; +use resource::{Resource, RouteId}; +use router::ResourceDef; use server::Request; -type ScopeResource = Rc>; +type ScopeResource = Rc>; type Route = Box>; -type ScopeResources = Rc)>>; -type NestedInfo = (Resource, Route, Vec>>); +type ScopeResources = Rc)>>; +type NestedInfo = (ResourceDef, Route, Vec>>); /// Resources scope /// @@ -147,7 +147,7 @@ impl Scope { })]; let handler = Box::new(Wrapper { scope, state }); self.nested - .push((Resource::prefix("", &path), handler, filters)); + .push((ResourceDef::prefix("", &path), handler, filters)); self } @@ -185,7 +185,7 @@ impl Scope { let filters = scope.take_filters(); self.nested - .push((Resource::prefix("", &path), Box::new(scope), filters)); + .push((ResourceDef::prefix("", &path), Box::new(scope), filters)); self } @@ -244,9 +244,9 @@ impl Scope { } } } else { - let mut handler = ResourceHandler::default(); + let mut handler = Resource::default(); handler.method(method).with(f); - let pattern = Resource::with_prefix( + let pattern = ResourceDef::with_prefix( handler.get_name(), path, if path.is_empty() { "" } else { "/" }, @@ -284,13 +284,13 @@ impl Scope { /// ``` pub fn resource(mut self, path: &str, f: F) -> Scope where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { // add resource handler - let mut handler = ResourceHandler::default(); + let mut handler = Resource::default(); f(&mut handler); - let pattern = Resource::with_prefix( + let pattern = ResourceDef::with_prefix( handler.get_name(), path, if path.is_empty() { "" } else { "/" }, @@ -306,10 +306,10 @@ impl Scope { /// Default resource to be used if no matching route could be found. pub fn default_resource(mut self, f: F) -> Scope where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { if self.default.is_none() { - self.default = Some(Rc::new(ResourceHandler::default_not_found())); + self.default = Some(Rc::new(Resource::default_not_found())); } { let default = Rc::get_mut(self.default.as_mut().unwrap()) @@ -439,7 +439,7 @@ struct ComposeInfo { id: RouteId, req: HttpRequest, mws: Rc>>>, - resource: Rc>, + resource: Rc>, } enum ComposeState { @@ -465,7 +465,7 @@ impl ComposeState { impl Compose { fn new( id: RouteId, req: HttpRequest, mws: Rc>>>, - resource: Rc>, + resource: Rc>, ) -> Self { let mut info = ComposeInfo { id, diff --git a/src/test.rs b/src/test.rs index 704292df1..4289bca88 100644 --- a/src/test.rs +++ b/src/test.rs @@ -27,7 +27,7 @@ use httpresponse::HttpResponse; use middleware::Middleware; use param::Params; use payload::Payload; -use resource::ResourceHandler; +use resource::Resource; use router::Router; use server::message::{Request, RequestPool}; use server::{HttpServer, IntoHttpHandler, ServerSettings}; @@ -353,7 +353,7 @@ impl TestApp { /// to `App::resource()` method. pub fn resource(&mut self, path: &str, f: F) -> &mut TestApp where - F: FnOnce(&mut ResourceHandler) -> R + 'static, + F: FnOnce(&mut Resource) -> R + 'static, { self.app = Some(self.app.take().unwrap().resource(path, f)); self