Allow any closure to be passed as an executor (#1686)

Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This commit is contained in:
Thomas Eizinger
2020-09-03 19:28:15 +10:00
committed by GitHub
parent 6a1279407e
commit 3100444085
3 changed files with 27 additions and 36 deletions

View File

@ -78,20 +78,8 @@ pub trait Executor {
fn exec(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
}
impl<'a, T: ?Sized + Executor> Executor for &'a T {
impl<F: Fn(Pin<Box<dyn Future<Output = ()> + Send>>)> Executor for F {
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {
T::exec(&**self, f)
}
}
impl<'a, T: ?Sized + Executor> Executor for &'a mut T {
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {
T::exec(&**self, f)
}
}
impl<T: ?Sized + Executor> Executor for Box<T> {
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {
T::exec(&**self, f)
self(f)
}
}