diff --git a/Cargo.lock b/Cargo.lock index 2a0a6d1..160b841 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "gotham-restful" -version = "0.1.0" +version = "0.0.1" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/lib.rs b/src/lib.rs index 34a8a73..ac691a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,4 +15,4 @@ mod result; pub use result::ResourceResult; mod routing; -pub use routing::ResourceRouter; +pub use routing::{DrawResources, DrawResourceRoutes}; diff --git a/src/routing.rs b/src/routing.rs index e312155..f9ba4bf 100644 --- a/src/routing.rs +++ b/src/routing.rs @@ -11,6 +11,15 @@ use mime::APPLICATION_JSON; use serde::Serialize; use std::panic::RefUnwindSafe; +/// This trait adds the `resource` method to gotham's routing. It allows you to register +/// any RESTful `Resource` with a path. +pub trait DrawResources +{ + fn resource(&mut self, path : T); +} + +/// This trait allows to draw routes within an resource. Use this only inside the +/// `Resource::setup` method. pub trait DrawResourceRoutes { fn index, IR : IndexResource>(&mut self); @@ -49,6 +58,17 @@ where macro_rules! implDrawResourceRoutes { ($implType:ident) => { + impl<'a, C, P> DrawResources for $implType<'a, C, P> + where + C : PipelineHandleChain

+ Copy + Send + Sync + 'static, + P : RefUnwindSafe + Send + Sync + 'static + { + fn resource(&mut self, path : T) + { + R::setup(); + } + } + impl<'a, C, P> DrawResourceRoutes for ($implType<'a, C, P>, String) where C : PipelineHandleChain

+ Copy + Send + Sync + 'static, @@ -65,29 +85,3 @@ macro_rules! implDrawResourceRoutes { implDrawResourceRoutes!(RouterBuilder); implDrawResourceRoutes!(ScopeBuilder); - -/// Allows you to setup routes inside a RESTful `Resource`. Currently supported are -/// index (GET without any id), get (GET with an id) and post (POST with a body). -pub struct ResourceSetupRoutes -{ - route : D, - path : String -} - -/// This trait adds the `resource` method to gotham's routing. It allows you to register -/// any RESTful `Resource` with a path. -pub trait ResourceRouter -{ - fn resource(&mut self, path : &str); -} - -fn resource(route : D, path : T) -where - C : PipelineHandleChain

+ Copy + Send + Sync + 'static, - P : RefUnwindSafe + Send + Sync + 'static, - D : DrawRoutes, - R : Resource, - T : ToString -{ - R::setup(); -}