use core::ops::{
Deref, DerefMut
};
use crate::{
cdef::Status,
Thread,
};
#[derive(Debug)]
#[repr(transparent)]
pub struct Coroutine<'l> {
thread: &'l mut Thread,
}
impl<'l> Coroutine<'l> {
pub const fn new(thread: &'l mut Thread) -> Self {
Self {
thread,
}
}
}
impl AsRef<Thread> for Coroutine<'_> {
fn as_ref(&self) -> &Thread {
self.thread
}
}
impl AsMut<Thread> for Coroutine<'_> {
fn as_mut(&mut self) -> &mut Thread {
self.thread
}
}
impl Deref for Coroutine<'_> {
type Target = Thread;
fn deref(&self) -> &Self::Target {
self.thread
}
}
impl DerefMut for Coroutine<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.thread
}
}
impl Coroutine<'_> {
pub fn close(&mut self) -> Status {
self.thread.close_as_coroutine()
}
pub fn close_from(&mut self, from: &Self) -> Status {
self.thread.close_as_coroutine_from(from.thread)
}
}