diff --git a/src/asynch.rs b/src/asynch.rs index 6afa346..19ae5a4 100644 --- a/src/asynch.rs +++ b/src/asynch.rs @@ -16,31 +16,49 @@ mod unblocker { use core::future::Future; pub trait Unblocker { - type UnblockFuture: Future + Send + type UnblockFuture<'a, F, T>: Future + Send where - T: Send; + Self: 'a, + F: Send + 'a, + T: Send + 'a; - fn unblock(&self, f: F) -> Self::UnblockFuture + fn unblock<'a, F, T>(&'a self, f: F) -> Self::UnblockFuture<'a, F, T> where - F: FnOnce() -> T + Send + 'static, - T: Send + 'static; + F: FnOnce() -> T + Send + 'a, + T: Send + 'a; } impl Unblocker for &U where U: Unblocker, { - type UnblockFuture - = U::UnblockFuture where T: Send; + type UnblockFuture<'a, F, T> + = U::UnblockFuture<'a, F, T> where Self: 'a, F: Send + 'a, T: Send + 'a; - fn unblock(&self, f: F) -> Self::UnblockFuture + fn unblock<'a, F, T>(&'a self, f: F) -> Self::UnblockFuture<'a, F, T> where - F: FnOnce() -> T + Send + 'static, - T: Send + 'static, + F: FnOnce() -> T + Send + 'a, + T: Send + 'a, { (*self).unblock(f) } } + + impl Unblocker for &mut U + where + U: Unblocker, + { + type UnblockFuture<'a, F, T> + = U::UnblockFuture<'a, F, T> where Self: 'a, F: Send + 'a, T: Send + 'a; + + fn unblock<'a, F, T>(&'a self, f: F) -> Self::UnblockFuture<'a, F, T> + where + F: FnOnce() -> T + Send + 'a, + T: Send + 'a, + { + (**self).unblock(f) + } + } } #[cfg(feature = "embedded-svc")] @@ -55,13 +73,13 @@ mod embedded_svc_compat { where U: embedded_svc::executor::asynch::Unblocker, { - type UnblockFuture = impl Future + Send - where T: Send; + type UnblockFuture<'a, F, T> = impl Future + Send + where Self: 'a, F: Send + 'a, T: Send + 'a; - fn unblock(&self, f: F) -> Self::UnblockFuture + fn unblock<'a, F, T>(&'a self, f: F) -> Self::UnblockFuture<'a, F, T> where - F: FnOnce() -> T + Send + 'static, - T: Send + 'static, + F: FnOnce() -> T + Send + 'a, + T: Send + 'a, { self.0.unblock(f) } @@ -71,13 +89,13 @@ mod embedded_svc_compat { where U: Unblocker, { - type UnblockFuture = impl Future + Send - where T: Send; + type UnblockFuture<'a, F, T> = impl Future + Send + where Self: 'a, F: Send + 'a, T: Send + 'a; - fn unblock(&self, f: F) -> Self::UnblockFuture + fn unblock<'a, F, T>(&'a self, f: F) -> Self::UnblockFuture<'a, F, T> where - F: FnOnce() -> T + Send + 'static, - T: Send + 'static, + F: FnOnce() -> T + Send + 'a, + T: Send + 'a, { self.0.unblock(f) }