mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
Merge branch 'master' into openapi
This commit is contained in:
commit
24f8fd96db
4 changed files with 44 additions and 18 deletions
28
src/helper.rs
Normal file
28
src/helper.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! rest_struct {
|
||||
($struct_name:ident { $($field_id:ident : $field_ty:ty),* }) => {
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
struct $struct_name
|
||||
{
|
||||
$($field_id : $field_ty),*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! rest_resource {
|
||||
($res_name:ident, $route:ident => $setup:block) => {
|
||||
struct $res_name;
|
||||
|
||||
impl ::gotham_restful::Resource for $res_name
|
||||
{
|
||||
fn name() -> String
|
||||
{
|
||||
stringify!($res_name).to_string()
|
||||
}
|
||||
|
||||
fn setup<D : ::gotham_restful::DrawResourceRoutes>(mut $route : D) $setup
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
pub use hyper::StatusCode;
|
||||
|
||||
pub mod helper;
|
||||
|
||||
#[cfg(feature = "openapi")]
|
||||
pub mod openapi;
|
||||
#[cfg(feature = "openapi")]
|
||||
|
|
|
@ -7,6 +7,11 @@ use std::panic::RefUnwindSafe;
|
|||
/// allow you to register the different methods for this Resource.
|
||||
pub trait Resource
|
||||
{
|
||||
/// The name of this resource. Must be unique.
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue