Skip to main content

dope_core/executor/task/future/
mod.rs

1use core::{future, marker, pin, task};
2
3use crate::executor::task::Fiber;
4
5/// Capabilities used by generated fiber adapters.
6pub mod raw;
7
8#[pin_project::pin_project]
9#[repr(transparent)]
10#[doc(hidden)]
11#[must_use = "futures do nothing unless you `.await` or poll them"]
12pub struct Awaitable<'a, 'd, I, F, const REPEAT: bool> {
13    #[pin]
14    fiber: F,
15    marker: marker::PhantomData<&'a mut self::raw::Brand<'d, I>>,
16}
17
18impl<'a, 'd, I, F, const REPEAT: bool> future::Future for Awaitable<'a, 'd, I, F, REPEAT>
19where
20    F: Fiber<'d>,
21{
22    type Output = F::Output;
23
24    fn poll(
25        self: pin::Pin<&mut Self>,
26        context: &mut task::Context<'_>,
27    ) -> task::Poll<Self::Output> {
28        // SAFETY: the affine brand admits this awaitable only inside its paired
29        // adapter poll, whose waker data is the live frame with the same scope.
30        let frame = unsafe {
31            &mut *context
32                .waker()
33                .data()
34                .cast_mut()
35                .cast::<self::raw::Frame<'_, '_, 'd, I>>()
36        };
37        frame.poll::<F, REPEAT>(self.project().fiber)
38    }
39}