Created
March 17, 2017 13:13
-
-
Save felipesere/765ba398cf0ac716aaa3bcdde963b13a to your computer and use it in GitHub Desktop.
Errors I am getting when trying to use an enum with Diesel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> This is the `enum` I am trying write/read to the DB | |
#[derive(Clone, Copy)] | |
#[repr(i16)] | |
pub enum Kind { | |
Technical = 1, | |
Client = 2, | |
Community = 3, | |
} | |
impl AsExpression<SmallInt> for Kind { | |
type Expression = AsExprOf<i16, SmallInt>; | |
fn as_expression(self) -> Self::Expression { | |
AsExpression::<SmallInt>::as_expression(*self as i16) | |
} | |
} | |
impl FromSql<SmallInt, Pg> for Kind { | |
fn from_sql(bytes: Option<&[u8]>) -> Result<Self, Box<Error+Send+Sync>> { | |
Ok(Kind::Technical) | |
} | |
} | |
> it is part of this larger structure: | |
#[derive(Serialize, Clone)] | |
#[derive(Queryable, Insertable)] | |
#[table_name = "questions"] | |
pub struct Question { | |
pub id: i32, | |
pub phrase: String, | |
pub kind: Kind, # <-- This is where I embedd the enum | |
} | |
> These are the erorrs I am getting now (selection, just the first few) | |
error[E0277]: the trait bound `questions::Kind: diesel::Expression` is not satisfied | |
--> src/models.rs:25:21 | |
| | |
25 | #[derive(Queryable, Insertable)] | |
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `questions::Kind` | |
| | |
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert questions::Kind` | |
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::SmallInt>>` for `&'insert questions::Kind` | |
= note: this error originates in a macro outside of the current crate | |
error[E0277]: the trait bound `&'insert models::Question: diesel::Insertable<schema::questions::table, DB>` is not satisfied | |
--> src/models.rs:25:21 | |
| | |
25 | #[derive(Queryable, Insertable)] | |
| ^^^^^^^^^^ the trait `diesel::Insertable<schema::questions::table, DB>` is not implemented for `&'insert models::Question` | |
| | |
= help: the following implementations were found: | |
<&'insert models::Question as diesel::Insertable<schema::questions::table, DB>> | |
= note: required by `diesel::Insertable` | |
= note: this error originates in a macro outside of the current crate | |
error[E0277]: the trait bound `questions::Kind: diesel::Expression` is not satisfied | |
--> src/models.rs:25:21 | |
| | |
25 | #[derive(Queryable, Insertable)] | |
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `questions::Kind` | |
| | |
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert questions::Kind` | |
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Nullable<diesel::types::SmallInt>>` for `&'insert questions::Kind` | |
= note: this error originates in a macro outside of the current crate | |
error[E0277]: the trait bound `DB: diesel::backend::SupportsDefaultKeyword` is not satisfied | |
--> src/models.rs:25:21 | |
| | |
25 | #[derive(Queryable, Insertable)] | |
| ^^^^^^^^^^ the trait `diesel::backend::SupportsDefaultKeyword` is not implemented for `DB` | |
| | |
= help: consider adding a `where DB: diesel::backend::SupportsDefaultKeyword` bound | |
= note: required because of the requirements on the impl of `diesel::insertable::InsertValues<DB>` for `(diesel::insertable::ColumnInsertValue<schema::questions::columns::id, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Integer>, &i32>>, diesel::insertable::ColumnInsertValue<schema::questions::columns::phrase, diesel::expression::bound::Bound<diesel::types::Nullable<diesel::types::Text>, &std::string::String>>, diesel::insertable::ColumnInsertValue<schema::questions::columns::kind, &'insert questions::Kind>)` | |
= note: required by `diesel::insertable::InsertValues` | |
= note: this error originates in a macro outside of the current crate | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment