use std::{pin::Pin, ptr::NonNull, task::Poll}; use futures_core::{Future, Wake}; use lifetime_guard::{atomic_guard::AtomicValueGuard, guard::ValueGuard}; pub mod block_on; pub mod maybe_done; pub type WakePtr = Option>; pub type LocalWaker = ValueGuard; pub type AtomicWaker = AtomicValueGuard; pub(crate) fn assert_future(future: F) -> F where F: Future, { future } pub struct PollFn(F) where F: FnMut(&LocalWaker) -> Poll; impl futures_core::Future for PollFn where F: FnMut(&LocalWaker) -> Poll, { type Output = T; fn poll( self: Pin<&mut Self>, waker: Pin<&LocalWaker>, ) -> Poll { (unsafe { &mut self.get_unchecked_mut().0 })(&waker) } } pub fn poll_fn(f: F) -> impl futures_core::Future where F: FnMut(&LocalWaker) -> Poll, { PollFn(f) } pub struct DummyWaker; impl Wake for DummyWaker { fn wake(&self) { dbg!("awake!"); } } pub fn dummy_guard() -> ValueGuard { ValueGuard::new(NonNull::new(&mut DummyWaker as *mut dyn Wake)) }