-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
I have found these related issues/pull requests
Didn't find anything
Description
Currently, Executor
is implemented by these types:

Pool
stands out here because its implemented for the shared reference instead of a mutable reference, which makes sense.
The problem is that this inconsistency is making it hard to abstract over an Executor.
Say I wanna make a database newtype
pub struct Database<D> {
pub inner: D,
}
And implement my helper methods on it, where D is an executor.
impl<'e, D> Database<D>
where
for<'a> &'a mut D: Executor<'e, Database = Postgres>,
{
pub async fn get_user(&mut self) -> sqlx::Result<User> {
sqlx::query!(...)
.fetch(&mut self.inner)
.await
}
}
Now I either have to bind &D: Executor
or &mut D: Executor
here, and in either case it wont work for all types I need it to work with (in my actual scenario I need it to work both with PgPool
and PgListener
).
If &mut Pool
also implemented Executor
(just delegating to the &Pool
implementation) this would not be a problem since I could just bind &mut D: Executor
and it would work for all types.
This seemed like a simple enough thing to add, but when I tried it, the crate did not compile with these errors:
error[E0275]: overflow evaluating the requirement `for<'c> &'c mut Pool<_>: Executor<'c>`
Now I'm not very familiar with the internals of sqlx
but in my few days of using it, its not the first time I encounter this sort of error (#3973).
It's as if sqlx
is really pushing the compiler to its limits with trait resolving.
Has anyone had similar issues? Any ideas how this could be solved?
Prefered solution
Executor
implementation for &mut Pool
Is this a breaking change? Why or why not?
Implementing a trait is never a breaking change, so no