Diesel query fragment function return type auto inference #3661
Replies: 4 comments
-
So the first question is obviously: where should this live? I can see 3 options (associated with their advantages):
I think 3 would be my personal favorite here. |
Beta Was this translation helpful? Give feedback.
-
EDIT: Question solved by #3662 merge Second question is: how do we deal with inference around boolean expressions? We have these implementations for boolean expressions: diesel/diesel/src/expression_methods/bool_expression_methods.rs Lines 41 to 46 in a4e6131 diesel/diesel/src/expression/helper_types.rs Lines 97 to 98 in a4e6131 Latest design discussions on why we currently have this constraint: #2589 (comment) So that currently won't work with our basic I found a solution for this that widens the type inference capabilities of the It works with types that are That fixes our type inference issue with the helper types (it can now correctly be inferred in all cases), however that's technically a breaking change to this extent:
Side note: We could also choose to introduce a more general |
Beta Was this translation helpful? Give feedback.
-
Good work 👍 That looks really interesting. I'm currently out for holidays, but I will come back with a longer response as soon as I'm back. |
Beta Was this translation helpful? Give feedback.
-
So I had finally some time to look a bit closer on that implementation. Again: That's really good work 👍 I think it would be great to expose that as part of diesel itself, so variant 2 or 3. If you are interested in using this in other contexts as well we might implement it as separate crate in the main diesel repo, similar to what we have done with the I still need to review the code in depth and figure out some details, but that's something I can do as soon as we have a PR for that. |
Beta Was this translation helpful? Give feedback.
-
Heyy!
More and more I found myself getting bored having to write return types for query fragment functions, so yesterday I decided to do the not-boring thing that would enable not being bored anymore.
Meet my prototype of
diesel_auto_type
!and more:
https://github.com/Ten0/diesel_auto_type/blob/master/tests/test.rs
It reads through the
let
assignments and expressions of the function to infer the return expression type using the basic convention of the existence of a corresponding helper type, same path as the function for functions, andPascalCase
in thedsl
module for methods.Now there are some questions about how to move forward with this, I'm putting those as sub-threads below.
Beta Was this translation helpful? Give feedback.
All reactions