futures_util/future/
with_executor.rs1use futures_core::{Future, Poll};
2use futures_core::task;
3use futures_core::executor::Executor;
4
5#[derive(Debug)]
10#[must_use = "futures do nothing unless polled"]
11pub struct WithExecutor<F, E> where F: Future, E: Executor {
12 executor: E,
13 future: F
14}
15
16pub fn new<F, E>(future: F, executor: E) -> WithExecutor<F, E>
17 where F: Future,
18 E: Executor,
19{
20 WithExecutor { executor, future }
21}
22
23impl<F, E> Future for WithExecutor<F, E>
24 where F: Future,
25 E: Executor,
26{
27 type Item = F::Item;
28 type Error = F::Error;
29
30 fn poll(&mut self, cx: &mut task::Context) -> Poll<F::Item, F::Error> {
31 self.future.poll(&mut cx.with_executor(&mut self.executor))
32 }
33}