Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upDerive Insertable for struct / Arc / Rc rather then for plain reference #1501
Comments
This comment has been minimized.
|
I've been meaning to generate an impl on the struct as well as a reference to the struct. Would that sufficiently handle your use case? |
This comment has been minimized.
alleycat-at-git
commented
Feb 12, 2018
|
@sgrif Yeah, that would solve the issue |
weiznich
referenced this issue
Feb 20, 2018
Merged
Derive insertable also on the type, not only on the reference #1567
weiznich
closed this
in
#1567
Apr 2, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alleycat-at-git commentedJan 20, 2018
•
edited
Currently there's only implementation for
&'a structwhenInsertableis auto-derived https://github.com/diesel-rs/diesel/blob/master/diesel/src/macros/insertable.rs#L103This is kind of painful when working with multithreading, because multithreading doesn't understand lifetimes. E.g. I have this method:
I want to generalize all the async stuff into one method to reduce boilerplate. This function works fine for
'staticqueries:But this thing
let query = diesel::insert_into(users).values(&payload);isn't static, but has'alifetime that is equal to payload. To avoid this, I tried to implement smth like this:But this fails due to rust compile limitations
F: for<'a> Fn(&'a P) -> Q<'a> + Send + 'static, i.e. it doesn't allow to specify lifetime for generic parameter. The corresponding Rust RFC is in progress https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md.All this pain comes from the fact that I have to use reference to payload here
let query = diesel::insert_into(users).values(&payload);. Because only reference auto-derived for Insertable. If it was smth likestructorArceverything would work ok.Does it make sense to implement these?