pub trait Create<R: Resource<Self>>: Storage<R> {
// Required method
fn create(
&self,
input: R::Create,
ctx: &Context,
) -> impl Future<Output = Result<R, Self::Error>> + Send;
}Available on crate features
http and validation only.Expand description
POST /resource — persist a new row.
Implement it only if you route CREATE; a resource that
does not accept creates needs no impl at all.
ⓘ
impl Create<Todo> for App {
async fn create(&self, input: NewTodo, ctx: &Context) -> Result<Todo, Self::Error> {
sqlx::query_as("insert into todos …")
.bind(&input.message)
.fetch_one(&self.db)
.await
}
}Required Methods§
Sourcefn create(
&self,
input: R::Create,
ctx: &Context,
) -> impl Future<Output = Result<R, Self::Error>> + Send
fn create( &self, input: R::Create, ctx: &Context, ) -> impl Future<Output = Result<R, Self::Error>> + Send
Persist a new row, assigning its id.
The parsed body arrives as an argument, built by
Resource::Create’s FromRequest impl. ctx comes alongside it
for the principal, the tenant, and anything else bound to the
request.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".