Derive Macro diesel::expression::AsExpression

source ·
#[derive(AsExpression)]
{
    // Attributes available to this derive:
    #[diesel]
    #[sql_type]
}
Expand description

Implements all required variants of AsExpression

This derive will generate the following impls:

  • impl AsExpression<SqlType> for YourType
  • impl AsExpression<Nullable<SqlType>> for YourType
  • impl AsExpression<SqlType> for &'a YourType
  • impl AsExpression<Nullable<SqlType>> for &'a YourType
  • impl AsExpression<SqlType> for &'a &'b YourType
  • impl AsExpression<Nullable<SqlType>> for &'a &'b YourType

If your type is unsized, you can specify this by adding the annotation #[diesel(not_sized)] as attribute on the type. This will skip the impls for non-reference types.

Using this derive requires implementing the ToSql trait for your type.

§Attributes:

§Required container attributes

  • #[diesel(sql_type = SqlType)], to specify the sql type of the generated implementations. If the attribute exists multiple times impls for each sql type is generated.

§Optional container attributes

  • #[diesel(not_sized)], to skip generating impls that require that the type is Sized