1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 13:02:28 +00:00

have the setup method be a macro arg for now

This commit is contained in:
Dominic 2019-09-30 20:10:51 +02:00
parent e845d996d9
commit d2275df6ff
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 13 additions and 19 deletions

View file

@ -15,7 +15,13 @@ use log4rs::{
encode::pattern::PatternEncoder encode::pattern::PatternEncoder
}; };
rest_resource!{Users} rest_resource!{Users, route => {
route.read_all::<Self, _>();
route.read::<Self, _, _>();
route.create::<Self, _, _>();
route.update_all::<Self, _, _>();
route.update::<Self, _, _, _>();
}}
rest_struct!{User { rest_struct!{User {
username : String username : String
@ -87,18 +93,6 @@ impl ResourceDelete<u64, Success<()>> for Users
} }
} }
// impl Resource for Users
// {
// fn setup<D : DrawResourceRoutes>(mut route : D)
// {
// route.read_all::<Self, _>();
// route.read::<Self, _, _>();
// route.create::<Self, _, _>();
// route.update_all::<Self, _, _>();
// route.update::<Self, _, _, _>();
// }
// }
const ADDR : &str = "127.0.0.1:18080"; const ADDR : &str = "127.0.0.1:18080";
fn main() fn main()

View file

@ -12,7 +12,7 @@ macro_rules! rest_struct {
#[macro_export] #[macro_export]
macro_rules! rest_resource { macro_rules! rest_resource {
($res_name:ident) => { ($res_name:ident, $route:ident => $setup:block) => {
struct $res_name; struct $res_name;
impl ::gotham_restful::Resource for $res_name impl ::gotham_restful::Resource for $res_name
@ -22,10 +22,7 @@ macro_rules! rest_resource {
stringify!($res_name).to_string() stringify!($res_name).to_string()
} }
fn setup<D : ::gotham_restful::DrawResourceRoutes>(mut route : D) fn setup<D : ::gotham_restful::DrawResourceRoutes>(mut $route : D) $setup
{
unimplemented!();
}
} }
} }
} }

View file

@ -7,8 +7,11 @@ use std::panic::RefUnwindSafe;
/// allow you to register the different methods for this Resource. /// allow you to register the different methods for this Resource.
pub trait Resource pub trait Resource
{ {
/// The name of this resource. Must be unique.
fn name() -> String; fn name() -> String;
/// Setup all routes of this resource. Take a look at the rest_resource!
/// macro if you don't feel like caring yourself.
fn setup<D : DrawResourceRoutes>(route : D); fn setup<D : DrawResourceRoutes>(route : D);
} }