use std::future::Future;
use std::marker::PhantomData;
use super::{RuntimeLocal, RuntimePoll};
pub(crate) struct PollExecutor<R>(PhantomData<fn() -> R>);
impl<R> Clone for PollExecutor<R> {
fn clone(&self) -> Self {
*self
}
}
impl<R> Copy for PollExecutor<R> {}
impl<R, F> hyper::rt::Executor<F> for PollExecutor<R>
where
R: RuntimePoll,
F: Future<Output = ()> + Send + 'static,
{
fn execute(&self, fut: F) {
R::spawn_send(fut);
}
}
pub(crate) fn poll_executor<R: RuntimePoll>() -> PollExecutor<R> {
PollExecutor(PhantomData)
}
pub(crate) struct CompletionExecutor<R>(PhantomData<fn() -> R>);
impl<R> Clone for CompletionExecutor<R> {
fn clone(&self) -> Self {
*self
}
}
impl<R> Copy for CompletionExecutor<R> {}
impl<R, F> hyper::rt::Executor<F> for CompletionExecutor<R>
where
R: RuntimeLocal,
F: Future<Output = ()> + 'static,
{
fn execute(&self, fut: F) {
R::spawn_local(fut);
}
}
pub(crate) fn completion_executor<R: RuntimeLocal>() -> CompletionExecutor<R> {
CompletionExecutor(PhantomData)
}