I get this error:
#[derive(Insertable, Queryable, Identifiable, Debug, PartialEq)]
^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `std::string::String`
when I try to compile this struct
:
#[derive(Insertable, Queryable, Identifiable, Debug, PartialEq)]
#[table_name = "example_table"]
pub struct SigninLog {
pub id: i32,
pub user_group: UserRoleEnum,
pub created_at: Option<SystemTime>,
pub optional_data: Option<String>
}
Is it because it contains a custom enum
or an Option<String>
? And if that is the problem how can I solve it?
In general, in order to be able to #[derive(X)]
for a struct
, all its members must implement X
as well. This might not be the case with Insertable
, because it is not a standard trait, but you might want to verify this; in your case Insertable
is not implemented for the String
within optional_data
; it is implemented for Option<T>
, so the Option
enclosing it is not an issue.
You might want to implement Insertable
manually; I haven't used diesel
, though - there might be a simpler way to do this.