pub trait Resource:
Send
+ Sync
+ 'static {
const ACTIONS: &'static [Action] = Action::ALL;
// Provided methods
fn index(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn new(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn create(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn show(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn edit(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn update(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
fn destroy(_ctx: Context) -> impl Future<Output = Result<Response>> + Send { ... }
}Expand description
A controller for a RESTful resource, mounted with Router::resources.
Every action defaults to 404 Not Found, so implement only the ones you
need (and use Router::resources_only to avoid registering the rest):
use glacier::prelude::*;
struct Posts;
impl Resource for Posts {
async fn index(_ctx: Context) -> Result<Response> {
Ok(Response::text("all posts"))
}
async fn show(ctx: Context) -> Result<Response> {
let id: u64 = ctx.param_as("id")?;
Ok(Response::text(format!("post {id}")))
}
}Provided Associated Constants§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".