Hi,
I'm trying to implement an async DataLock (mutex like) machanism using Future
s. However, I've trouble implementing the Future with the required lifetime paramater on the output type.
This is what I got so far:
impl<'a, T: 'static> Future for AsyncDataLockFuture<'a, T> {
type Output = TryDataLock<'a, T>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut(); // <-- here I got an error, see below
}
}
I stripped a way some code but the issue is this:
cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
expected `core::pin::Pin<&mut asyncdatalock::AsyncDataLockFuture<'a, T>>`
found `core::pin::Pin<&mut asyncdatalock::AsyncDataLockFuture<'a, T>>`
expected `core::future::Future`
found `core::future::Future`rustc(E0495)
asyncdatalock.rs(119, 5): first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 119:5...
asyncdatalock.rs(120, 25): ...so that the types are compatible
asyncdatalock.rs(116, 6): but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 116:6...
asyncdatalock.rs(119, 79): ...so that the types are compatible
Well even if the actual
and expected
types in the message looks quite the same to me the issue seem to be the anonymous lifetime in the cx: &mut Context<'_>
part. But when handing here the 'a
lifetime the compiler complains that the signatures of the poll functions does not match between trait definition and implementation.
So any hint would be highly appreciated
Thanks in advance.