@teromene That works for the trait. But now I can not implement it for Postgres (the second link in the question): error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements (play.rust-lang.org/?version=ni)

@teromene I don't get it: your example works because you have not put in the `generate` generic function. If I put it back in, it does not compile: play.rust-lang.org/?version=ni

@kmk Sorry, didn't see your message.
The problem you have here is that you have a cyclic dependency on lifetimes:
You need to get the source, which borrows self for a.
Then, with the source, you call another function that must act on a, but self is already borrowed. You will need to make an allocation somewhere or use a "dynamic" borrow tool like an Rc

@teromene No need to be sorry, that's nice of you to be looking into this.
I'll try with boxing.
But what's puzzling me is that it works if I handwrite the specialized version (play.rust-lang.org/?version=ni) while the generic version does not. Shouldn't the problem be the same?

@kmk Not really.
Here you are creating "real" objects. So rust does the borrow check on the actual functions.
With the other one, rust cannot know in advance what your functions will look like, so it must assume the most liberal approach corresponding to your traits

@teromene And can't I limit the trait enough that it will fit like the "real" objects?

@kmk One of the thing you could do is to remove the `postgres::Transaction<'a>` and to replace it with a getter.
You would then be able to get it matching your local lifetime scope

Inscrivez-vous pour prendre part à la conversation

Le réseau social de l'avenir : Pas d'annonces, pas de surveillance institutionnelle, conception éthique et décentralisation ! Possédez vos données avec Mastodon !