I've been trying to write a serde Serializer, but running into problems. See this playground:
I cannot change the traits (they're part of serde), only the impls. So how do I fix the serialize_field() implementation so that the correct lifetime can be inferred? Conceptually the lifetimes should not be an issue, but I have not been able to figure out how to convey this to the compiler.
Basically what happened is that reborrowing with &mut **self you create a borrow of the original reference, possibly shortening the lifetime. In order to be able to pass it to serialize, you want the lifetime to be very short.
However the reborrow doesn't change the second lifetime in the type. The generic lifetime 'acan be shortened, but you'd have to manually shorten every field.
The thing is, your functions are written in a way that reuses the lifetime for both positions. This requires them to be the same lifetime, so since the generic lifetime is unchanged, the reference lifetime cannot be shortened.