pub trait Resource:
Send
+ Sync
+ 'static {
type State: Clone + Send + Sync + 'static;
type Id: DeserializeOwned + Send + Sync + 'static;
type Item: Serialize + Send + Sync + 'static;
type Create: DeserializeOwned + Send + Sync + 'static;
type Update: DeserializeOwned + Send + Sync + 'static;
// Required methods
fn index<'life0, 'async_trait>(
state: &'life0 Self::State,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Item>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn show<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn create<'life0, 'async_trait>(
state: &'life0 Self::State,
body: Self::Create,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn update<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
body: Self::Update,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn destroy<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A REST-ish resource controller: implement this once for a type and get
the five conventional CRUD routes (GET /x, GET /x/:id, POST /x,
PUT /x/:id, DELETE /x/:id) wired up for free via resource.
State is the app state (typically holding a crate::db::Db); Id is
the identifier as it appears in the URL; Item is the JSON shape
returned to clients; Create/Update are the accepted JSON bodies.
Required Associated Types§
type State: Clone + Send + Sync + 'static
type Id: DeserializeOwned + Send + Sync + 'static
type Item: Serialize + Send + Sync + 'static
type Create: DeserializeOwned + Send + Sync + 'static
type Update: DeserializeOwned + Send + Sync + 'static
Required Methods§
fn index<'life0, 'async_trait>(
state: &'life0 Self::State,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Item>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn show<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>(
state: &'life0 Self::State,
body: Self::Create,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
body: Self::Update,
) -> Pin<Box<dyn Future<Output = Result<Self::Item>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn destroy<'life0, 'async_trait>(
state: &'life0 Self::State,
id: Self::Id,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".