I don't know why you would get that error, maybe just forgot to save the file or something?
I think the function itself won't even compile, because fetch_one and execute expect an Executor, not a reference to one and references to Executors don't themselves implement Executor. You will almost certainly have to use Acquire instead - there are some example for using it in the docs.
I think because &Pool<Sqlite> is the only applicable implementor.
your trait bound is too specific, it explicitly requires the implementor to be a shared reference type:
where
&'e E: SqliteExecutor<'c>,
looking at the implementors of the trait, &Pool<_> is the only one in the form of shared reference, all other implementors are in the form of exclusive references, like &'c mut MysqlConnection, &'c mut SqliteConnection.
@nerditation I started with impl SqliteExecutor but my function calls two methods on Executor (fetch_one and execute) which consume it and so the second one ends with "use of moved value executor" error. This is why I started playing with references.
@jplatte thanks for the tip! It seems that Executor is not the right tool for this task and Acquire is the way to go. When I looked at definitions of fetch_one and execute I came to the wrong conclusion that I need to use Executor.
due to the way the Executor trait is defined, where all methods consumes self, it is not directly expressible using generics, since exlusive references and shared references are different.
in non-generic code, shared references are Copy, and exclusive references can be reborrowed, so it's ok to call the trait methods multiple times.
ideally, you want the Executor trait to get an update, but for now, you'll need to create another helper trait to abstract away the difference between the shared references and exclusive references. here's an example using GAT:
trait AsSqliteExecutor {
type Executor<'c>: SqliteExecutor<'c> where Self: 'c;
// use exclusive borrow `&mut self` so it can
fn as_sqlite_executor(&mut self) -> Self::Executor<'_>;
}
note this doesn't allow a blanket implementation, since the SqliteExecutor<'c> trait doesn't have an explicit reborrow method, so you have to manually implement it for the types you used, like &Pool<_> and &mut SqliteConnection.