Skip to content

Generic FilterDsl::filter() and FilterDsl<Output = ...> #3965

Answered by weiznich
JMLX42 asked this question in Q&A
Discussion options

You must be logged in to vote

I generally advice not to write such generic code (at least not for application code) as it involves these complex hard to write type bounds. That written: As you already noticed, each call of one of the QueryDsl methods changes the returned type. That's used by diesel to perform all these compile time checks. If you now write generic code you need to proof to the compiler that all these bounds hold, which is depending on the amount of methods you use a quite large task. You can make it a bit easier by boxing the query via QueryDsl::into_boxed(), as that "fixes" the query type to a (mostly) concrete type. By doing that I can modify your example to be something like that:

pub fn select_by_ids

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@JMLX42
Comment options

@weiznich
Comment options

Answer selected by JMLX42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants