Error .load::<Role>(&connection)

use crate::schema::roles;

#[derive(Queryable ,Serialize, Deserialize)]
pub struct Role {
pub id: i32,
pub title: String,
// pub created_at: String,
}

#[derive(Insertable)]
#[table_name=“roles”]
pub struct NewRole {
pub title: String,
}

#[derive(Serialize, Deserialize)]
pub struct RoleList(pub Vec);

impl RoleList {
pub fn list() -> Self {
use diesel::RunQueryDsl;
use diesel::QueryDsl;
use crate::schema::roles::dsl::*;
use crate::db_connection::establish_connection;

    let connection = establish_connection();

    let result = 
        roles
            .limit(10)
            .load::<Role>(&connection)
            .expect("Error loading Roles");

    RoleList(result)
}

}

error: the trait bound (i32, std::string::String): diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Timestamp), _> is not satisfied label: the trait diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Timestamp), _> is not implemented for (i32, std::string::String)

Hello! Welcome to the Rust programming language users forum. For all future posts, please surround large bodies of code in three ticks like so:

```
//Your code
```

So as to end up with formatting like the following:

fn main() {
    let x = String::new();
    x.push_str("ABC");
    println!("{:?}", x);
}

Or inline with a single tick:

This is some regular text followed by `code`

This is some regular text followed by code.

Thanks!

1 Like