dope-core 0.76.0

Owned native I/O and completion driver for dope
Documentation
use core::{future, marker, pin, task};

use crate::executor::task::Fiber;

/// Capabilities used by generated fiber adapters.
pub mod raw;

#[pin_project::pin_project]
#[repr(transparent)]
#[doc(hidden)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Awaitable<'a, 'd, I, F, const REPEAT: bool> {
    #[pin]
    fiber: F,
    marker: marker::PhantomData<&'a mut self::raw::Brand<'d, I>>,
}

impl<'a, 'd, I, F, const REPEAT: bool> future::Future for Awaitable<'a, 'd, I, F, REPEAT>
where
    F: Fiber<'d>,
{
    type Output = F::Output;

    fn poll(
        self: pin::Pin<&mut Self>,
        context: &mut task::Context<'_>,
    ) -> task::Poll<Self::Output> {
        // SAFETY: the affine brand admits this awaitable only inside its paired
        // adapter poll, whose waker data is the live frame with the same scope.
        let frame = unsafe {
            &mut *context
                .waker()
                .data()
                .cast_mut()
                .cast::<self::raw::Frame<'_, '_, 'd, I>>()
        };
        frame.poll::<F, REPEAT>(self.project().fiber)
    }
}