Skip to content

Using generic structs with Insertable #4446

Answered by weiznich
ahmed-said-jax asked this question in Q&A
Discussion options

You must be logged in to vote

The following definition works:

#[derive(Insertable)]
#[diesel(table_name = foo)]
#[diesel(check_for_backend(diesel::pg::Pg))]
struct NewFoo<Str: AsExpression<diesel::sql_types::Text>>
where
    for<'a> &'a Str: AsExpression<diesel::sql_types::Text>,
{
    name: Str,
}

We require bounds for the owned type and for the reference type as the insertable derive generates implementations for both NewFoo and &NewFoo.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ahmed-said-jax
Comment options

Answer selected by ahmed-said-jax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants