Skip to content

Arcane 'the trait bound is not satisfied' error while using Diesel

Published: at 09:23 AM

Symptoms

Given the following db model:

#[derive(Queryable, Debug, Identifiable, Clone)]
#[primary_key(doc_id)]
#[table_name = "biz"]
pub struct Biz {
    pub doc_id: u32,
    pub media_id: u32,
    pub num: u32,
    pub subnum: u32,
    pub thread_num: u32,
    pub op: bool,
    pub timestamp: u32,
    pub timestamp_expired: u32,
    pub preview_orig: Option<String>,
    pub preview_w: u16,
    pub preview_h: u16,
    pub media_filename: Option<String>,
    pub media_w: u16,
    pub media_h: u16,
    pub media_size: u32,
    pub media_hash: Option<String>,
    pub media_orig: Option<String>,
    pub spoiler: bool,
    pub deleted: bool,
    pub capcode: String,
    pub email: Option<String>,
    pub name: Option<String>,
    pub trip: Option<String>,
    pub title: Option<String>,
    pub comment: Option<String>,
    pub delpass: Option<String>,
    pub sticky: bool,
    pub locked: bool,
    pub poster_hash: Option<String>,
    pub poster_country: Option<String>,
    pub exif: Option<String>,
    // pub unix_timestamp: NaiveDateTime,
}

And the table! macro with:

table! {
    biz (doc_id) {
        doc_id -> Unsigned<Integer>,
        media_id -> Unsigned<Integer>,
        num -> Unsigned<Integer>, // <-- accidentaly removed subnum here
        thread_num -> Unsigned<Integer>,
        op -> Bool,
        timestamp -> Unsigned<Integer>,
        timestamp_expired -> Unsigned<Integer>,
        preview_orig -> Nullable<Varchar>,
        preview_w -> Unsigned<Smallint>,
        preview_h -> Unsigned<Smallint>,
        media_filename -> Nullable<Text>,
        media_w -> Unsigned<Smallint>,
        media_h -> Unsigned<Smallint>,
        media_size -> Unsigned<Integer>,
        media_hash -> Nullable<Varchar>,
        media_orig -> Nullable<Varchar>,
        spoiler -> Bool,
        deleted -> Bool,
        capcode -> Varchar,
        email -> Nullable<Varchar>,
        name -> Nullable<Varchar>,
        trip -> Nullable<Varchar>,
        title -> Nullable<Varchar>,
        comment -> Nullable<Text>,
        delpass -> Nullable<Tinytext>,
        sticky -> Bool,
        locked -> Bool,
        poster_hash -> Nullable<Varchar>,
        poster_country -> Nullable<Varchar>,
        exif -> Nullable<Text>,
        // unix_timestamp -> Datetime,
    }
}

This error happens:

Checking hesoyam v0.2.0 (/home/jakub/dev/hesoyam-suite/backend)
error[E0277]: the trait bound `(u32, u32, u32, u32, u32, bool, u32, u32, std::option::Option<std::string::String>, u16, u16, std::option::Option<std::string::String>, u16, u16, u32, std::option::Option<std::string::String>, std::option::Option<std::string::String>, bool, bool, std::string::String, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, bool, bool, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>): Queryable<(diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Bool, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` is not satisfied
    --> src/models/biz.rs:62:14
     |
62   |             .load::<Biz>(connection)
     |              ^^^^ the trait `Queryable<(diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Bool, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` is not implemented for `(u32, u32, u32, u32, u32, bool, u32, u32, std::option::Option<std::string::String>, u16, u16, std::option::Option<std::string::String>, u16, u16, u32, std::option::Option<std::string::String>, std::option::Option<std::string::String>, bool, bool, std::string::String, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>, bool, bool, std::option::Option<std::string::String>, std::option::Option<std::string::String>, std::option::Option<std::string::String>)`
     |
     = help: the following implementations were found:
               <(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, AA, AB, AC, AD, AE) as Queryable<(SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SP, SQ, SR, SS, ST, SU, SV, SW, SX, SY, SZ, SAA, SAB, SAC, SAD, SAE), __DB>>
note: required because of the requirements on the impl of `Queryable<(diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Bool, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<SmallInt>, diesel::sql_types::Unsigned<diesel::sql_types::Integer>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` for `Biz`
    --> src/models/biz.rs:5:10
     |
5    | #[derive(Queryable, Debug, Identifiable, Clone)]
     |          ^^^^^^^^^

Fix

This was caused by the mismatch of props in table! and in Biz model. I’ve removed the poster_ip property from the macro (The type was Unsigned<Decimal> and I couldn’t map it some available rust type). Accidentally, i also removed the subnum property from table! macro, which caused the error. So if this error happens, check if the props in table! and in model are matching.