ruloom 0.1.2

A thin wrapper around 'corosensei' that provides support for stackful coroutines in Rust (like Loom in Java or goroutines in golang).
Documentation
use std::{cell::Cell, task::Waker};

thread_local! {
    static WAKERS: Cell<Option<&'static Waker>> = const { Cell::new(None) };
}

pub(crate) struct ThreadLocalWaker;

impl ThreadLocalWaker {
    #[inline]
    pub unsafe fn set(waker: &Waker) {
        let static_waker: &'static Waker = std::mem::transmute(waker);
        WAKERS.with(|w| {
            w.set(Some(static_waker));
        });
    }

    #[inline]
    pub fn remove() {
        WAKERS.with(|cell| {
            cell.set(None);
        });
    }

    #[inline]
    pub unsafe fn get_expect_present() -> &'static Waker {
        WAKERS.with(|cell| {
            cell.get()
                .expect("There's no waker for the current thread.")
        })
    }
}