Replies: 1 comment
-
|
A modification of your first example which omits the lifetime arguments altogether will now compile with async fn does_not_work_in_08x_but_does_in_09x<'c, E, DB>(executor: E)
where
E: Executor<'c, Database = DB>,
DB: Database,
<DB as Database>::Arguments: IntoArguments<DB>,
{
let mut builder = QueryBuilder::new("");
let _ = executor.fetch_one(builder.build()).await;
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I'm currently having an issue with using
QueryBuilderin conjunction with generics. Consider the following minimal example:This causes the compiler to complain that "
builderdoes not live long enough", as apparently it's dropped when the function ends, but is still borrowed (according to the compiler anyway).I can work around this, by adding
'ctoArguments, like so:This lets me compile the function, but calling it with the
Sqlitedriver causes another compilation error, namely that "implementation ofIntoArgumentsis not general enough".Converting
'qto be a named lifetime does not work either:As in this scenario, the compiler mentions that "
builderdoes not live long enough" as "argument requires thatbuilderis borrowed for'q".Finally, for good measure, if I just specify the
Sqlitedriver directly, the function does compile and can be called properly:But obviously, the latter is undesirable, as it is meant to be a driver-agnostic function.
My question is: What am I missing here? I was looking at sqlx' trait bounds for
Database,Arguments,IntoArguments,Execute, andExecutorbut didn't manage to find anything. Is it even possible to get a function like this to compile with the current API?Beta Was this translation helpful? Give feedback.
All reactions