mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
get rid of some useless stuff
This commit is contained in:
parent
4121001244
commit
5ef80deecf
3 changed files with 22 additions and 28 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -292,7 +292,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gotham-restful"
|
name = "gotham-restful"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -15,4 +15,4 @@ mod result;
|
||||||
pub use result::ResourceResult;
|
pub use result::ResourceResult;
|
||||||
|
|
||||||
mod routing;
|
mod routing;
|
||||||
pub use routing::ResourceRouter;
|
pub use routing::{DrawResources, DrawResourceRoutes};
|
||||||
|
|
|
@ -11,6 +11,15 @@ use mime::APPLICATION_JSON;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::panic::RefUnwindSafe;
|
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<R : Resource, T : ToString>(&mut self, path : T);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This trait allows to draw routes within an resource. Use this only inside the
|
||||||
|
/// `Resource::setup` method.
|
||||||
pub trait DrawResourceRoutes
|
pub trait DrawResourceRoutes
|
||||||
{
|
{
|
||||||
fn index<R : Serialize, E : Serialize, Res : ResourceResult<R, E>, IR : IndexResource<R, E, Res>>(&mut self);
|
fn index<R : Serialize, E : Serialize, Res : ResourceResult<R, E>, IR : IndexResource<R, E, Res>>(&mut self);
|
||||||
|
@ -49,6 +58,17 @@ where
|
||||||
|
|
||||||
macro_rules! implDrawResourceRoutes {
|
macro_rules! implDrawResourceRoutes {
|
||||||
($implType:ident) => {
|
($implType:ident) => {
|
||||||
|
impl<'a, C, P> DrawResources for $implType<'a, C, P>
|
||||||
|
where
|
||||||
|
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
|
||||||
|
P : RefUnwindSafe + Send + Sync + 'static
|
||||||
|
{
|
||||||
|
fn resource<R : Resource, T : ToString>(&mut self, path : T)
|
||||||
|
{
|
||||||
|
R::setup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, C, P> DrawResourceRoutes for ($implType<'a, C, P>, String)
|
impl<'a, C, P> DrawResourceRoutes for ($implType<'a, C, P>, String)
|
||||||
where
|
where
|
||||||
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
|
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
|
||||||
|
@ -65,29 +85,3 @@ macro_rules! implDrawResourceRoutes {
|
||||||
|
|
||||||
implDrawResourceRoutes!(RouterBuilder);
|
implDrawResourceRoutes!(RouterBuilder);
|
||||||
implDrawResourceRoutes!(ScopeBuilder);
|
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<D : DrawResourceRoutes>
|
|
||||||
{
|
|
||||||
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<R : Resource>(&mut self, path : &str);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resource<D, C, P, R, T>(route : D, path : T)
|
|
||||||
where
|
|
||||||
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
|
|
||||||
P : RefUnwindSafe + Send + Sync + 'static,
|
|
||||||
D : DrawRoutes<C, P>,
|
|
||||||
R : Resource,
|
|
||||||
T : ToString
|
|
||||||
{
|
|
||||||
R::setup();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue