New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not insert with mut reference using values #1214

Closed
xinghun92 opened this Issue Sep 27, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@xinghun92

xinghun92 commented Sep 27, 2017

This code can not compile.

fn test_insert_mut_users(users: &mut [::NewUser]) {
    let conn = ::establish_connection();
    ::diesel::replace_into(::users::table).values(users).execute(&conn).unwrap();
}

#[test]
fn test_insert_mut() {
    let mut users = ::create_new_users(10);
    test_insert_mut_users(&mut users);
}

The error is

::diesel::replace_into(::users::table).values(users).execute(&conn).unwrap();
    |                                                ^^^^^^ the trait `diesel::Insertable<__diesel_infer_schema::infer_users::users::table>` is not implemented for `&mut [NewUser<'_>]`

And insert _or_replace works well

fn test_insert_mut_users(users: &mut [::NewUser]) {
    let conn = ::establish_connection();
    ::diesel::insert_or_replace(users).into(::users::table).execute(&conn).unwrap();
}

And I must uselet users = Vec::from(users) before insert, I think the ergonomics is bad.

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 27, 2017

Changing users to &*users will fix it.

@sgrif sgrif closed this Sep 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment