Skip to content

Commit

Permalink
Compat with latest embedded-svc
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Oct 10, 2023
1 parent 27d428c commit 039bb09
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions src/asynch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,49 @@ mod unblocker {
use core::future::Future;

pub trait Unblocker {
type UnblockFuture<T>: Future<Output = T> + Send
type UnblockFuture<'a, F, T>: Future<Output = T> + Send
where
T: Send;
Self: 'a,
F: Send + 'a,
T: Send + 'a;

fn unblock<F, T>(&self, f: F) -> Self::UnblockFuture<T>
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<U> Unblocker for &U
where
U: Unblocker,
{
type UnblockFuture<T>
= U::UnblockFuture<T> where T: Send;
type UnblockFuture<'a, F, T>
= U::UnblockFuture<'a, F, T> where Self: 'a, F: Send + 'a, T: Send + 'a;

fn unblock<F, T>(&self, f: F) -> Self::UnblockFuture<T>
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<U> 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")]
Expand All @@ -55,13 +73,13 @@ mod embedded_svc_compat {
where
U: embedded_svc::executor::asynch::Unblocker,
{
type UnblockFuture<T> = impl Future<Output = T> + Send
where T: Send;
type UnblockFuture<'a, F, T> = impl Future<Output = T> + Send
where Self: 'a, F: Send + 'a, T: Send + 'a;

fn unblock<F, T>(&self, f: F) -> Self::UnblockFuture<T>
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)
}
Expand All @@ -71,13 +89,13 @@ mod embedded_svc_compat {
where
U: Unblocker,
{
type UnblockFuture<T> = impl Future<Output = T> + Send
where T: Send;
type UnblockFuture<'a, F, T> = impl Future<Output = T> + Send
where Self: 'a, F: Send + 'a, T: Send + 'a;

fn unblock<F, T>(&self, f: F) -> Self::UnblockFuture<T>
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)
}
Expand Down

0 comments on commit 039bb09

Please sign in to comment.