I apologize in advance if the code seems confusing or complex for no apparent reason: this is just a minimal example compared to the real code (which is much more complex and bigger).
I would like to understand why this error:
error: `impl Executor` does not live long enough
--> src/main.rs:136:5
|
136 | / async move {
137 | | dbg!("I'm:", user);
138 | |
139 | | let mut store = store.unwrap_or_default();
... |
169 | | }
170 | | .boxed()
| |____________^
The reason I'm using the trait Executor is because I need to use both DB connections and transactions in my services layer (represented here by team_list).
I can change everything in this code, the trait too.
I have tested and found that the db.as_executor() passed in when calling fetch_all caused the lifetime check to fail.
Is it because of the lifetime 'this defined in the associated type, or because of the lifetime restriction in sqlx::executor::Executor<'c> ? Thank you for your reply
My original reply is too far out of cache for me to be sure, but I probably just got something I could recreate in the playground, didn't see why it shouldn't logically work, found the issues and read them to try and understand more, read
This code worked with some earlier version of nightly Rust (without the where Self: 'a bound, and before where Self: 'a was required in the GAT). Unfortunately I do not remember which version that was (a few weeks ago).
in one of the issues and tried disabling the lint that requires the bound (which isn't something you should need special knowledge to do if it was better designed IMNSHO) and removing the bound in my reproduction, and it worked.
I guess that's a long-winded way of saying I can't explain why it works, but had enough experience and tenacity to find a workaround that at least compiled (so might work in your actual use case).
Almost surely that was so I didn't have to try and mock up PgExecutor<'_> in the playground, and I just failed to uncomment it in my comment here.