1use std::future::Future;
4
5use crate::context::Context;
6use crate::error::{Error, Result};
7use crate::response::Response;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum Action {
12 Index,
13 New,
14 Create,
15 Show,
16 Edit,
17 Update,
18 Destroy,
19}
20
21impl Action {
22 pub const ALL: &'static [Action] = &[
23 Action::Index,
24 Action::New,
25 Action::Create,
26 Action::Show,
27 Action::Edit,
28 Action::Update,
29 Action::Destroy,
30 ];
31}
32
33pub trait Resource: Send + Sync + 'static {
55 const ACTIONS: &'static [Action] = Action::ALL;
58
59 fn index(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
61 async { Err(Error::not_found()) }
62 }
63
64 fn new(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
66 async { Err(Error::not_found()) }
67 }
68
69 fn create(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
71 async { Err(Error::not_found()) }
72 }
73
74 fn show(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
76 async { Err(Error::not_found()) }
77 }
78
79 fn edit(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
81 async { Err(Error::not_found()) }
82 }
83
84 fn update(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
86 async { Err(Error::not_found()) }
87 }
88
89 fn destroy(_ctx: Context) -> impl Future<Output = Result<Response>> + Send {
91 async { Err(Error::not_found()) }
92 }
93}