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

#insert error: unable to infer enough type information about `_` #8

Closed
mfpiccolo opened this Issue Nov 27, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@mfpiccolo
Collaborator

mfpiccolo commented Nov 27, 2015

@sgrif I am setting up a simple server with yaqb and I am running into a problem with insert that I cannot get past. I ultimately keep running into this error when trying to use insert with a NewUser struct.

src/models/user.rs:41:10: 41:49 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
src/models/user.rs:41     conn.insert(&self::users::table, &new_users);

If I switch to insert_returning_count it works fine.

Here is the line causing the error:

https://github.com/mfpiccolo/yaqb_test/blob/master/src/models/user.rs#L40

@mfpiccolo

This comment has been minimized.

Collaborator

mfpiccolo commented Nov 27, 2015

It also compiles if I set a return value for the function:

pub fn insert(new_users: Vec<NewUser>) -> Vec<User> {
  User::conn().insert(&self::users::table, &new_users).unwrap().collect()
}
@sgrif

This comment has been minimized.

Member

sgrif commented Nov 27, 2015

This is a hole in the docs. If you're not going to use the return value, you should use insert_returning_count (which I'm open to other names for as well). insert is only intended to be used when you need the created record (either for ids, timestamps, or the result of some default value)

@sgrif sgrif closed this Nov 27, 2015

@sgrif sgrif reopened this Nov 27, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Nov 27, 2015

Leaving this open since there's an actionable problem

@sgrif sgrif added this to the 0.1 milestone Nov 28, 2015

@sgrif

This comment has been minimized.

Member

sgrif commented Nov 28, 2015

Fixed by 58b73cb

@sgrif sgrif closed this Nov 28, 2015

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