diff --git a/derive/src/resource.rs b/derive/src/resource.rs index a51ecbb..79482e6 100644 --- a/derive/src/resource.rs +++ b/derive/src/resource.rs @@ -48,11 +48,6 @@ pub fn expand_resource(input : DeriveInput) -> Result Ok(quote! { impl #krate::Resource for #ident { - fn name() -> String - { - stringify!(#ident).to_string() - } - fn setup(mut route : D) { #(#methods)* diff --git a/src/resource.rs b/src/resource.rs index 6e2d5cd..daedd3d 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -9,18 +9,22 @@ use std::{ pin::Pin }; -/// This trait must be implemented by every RESTful Resource. It will -/// allow you to register the different methods for this Resource. +/// This trait must be implemented for every resource. It allows you to register the different +/// methods that can be handled by this resource to be registered with the underlying router. +/// +/// It is not recommended to implement this yourself, rather just use `#[derive(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. + /// Register all methods handled by this resource with the underlying router. fn setup(route : D); } +/// A common trait for every resource method. It defines the return type as well as some general +/// information about a resource method. +/// +/// It is not recommended to implement this yourself. Rather, just write your handler method and +/// annotate it with `#[(YourResource)]`, where `` is one of the supported +/// resource methods. pub trait ResourceMethod { type Res : ResourceResult + Send + 'static; @@ -37,63 +41,78 @@ pub trait ResourceMethod } } -/// Handle a GET request on the Resource root. +/// The read_all [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceReadAll : ResourceMethod { + /// Handle a GET request on the Resource root. fn read_all(state : State) -> Pin + Send>>; } -/// Handle a GET request on the Resource with an id. +/// The read [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceRead : ResourceMethod { + /// The ID type to be parsed from the request path. type ID : ResourceID + 'static; + /// Handle a GET request on the Resource with an id. fn read(state : State, id : Self::ID) -> Pin + Send>>; } -/// Handle a GET request on the Resource with additional search parameters. +/// The search [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceSearch : ResourceMethod { + /// The Query type to be parsed from the request parameters. type Query : ResourceType + QueryStringExtractor + Sync; + /// Handle a GET request on the Resource with additional search parameters. fn search(state : State, query : Self::Query) -> Pin + Send>>; } -/// Handle a POST request on the Resource root. +/// The create [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceCreate : ResourceMethod { + /// The Body type to be parsed from the request body. type Body : RequestBody; + /// Handle a POST request on the Resource root. fn create(state : State, body : Self::Body) -> Pin + Send>>; } -/// Handle a PUT request on the Resource root. +/// The change_all [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceChangeAll : ResourceMethod { + /// The Body type to be parsed from the request body. type Body : RequestBody; + /// Handle a PUT request on the Resource root. fn change_all(state : State, body : Self::Body) -> Pin + Send>>; } -/// Handle a PUT request on the Resource with an id. +/// The change [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceChange : ResourceMethod { + /// The Body type to be parsed from the request body. type Body : RequestBody; + /// The ID type to be parsed from the request path. type ID : ResourceID + 'static; + /// Handle a PUT request on the Resource with an id. fn change(state : State, id : Self::ID, body : Self::Body) -> Pin + Send>>; } -/// Handle a DELETE request on the Resource root. +/// The remove_all [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceRemoveAll : ResourceMethod { + /// Handle a DELETE request on the Resource root. fn remove_all(state : State) -> Pin + Send>>; } -/// Handle a DELETE request on the Resource with an id. +/// The remove [`ResourceMethod`](trait.ResourceMethod.html). pub trait ResourceRemove : ResourceMethod { + /// The ID type to be parsed from the request path. type ID : ResourceID + 'static; + /// Handle a DELETE request on the Resource with an id. fn remove(state : State, id : Self::ID) -> Pin + Send>>; }