#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct Transfer
{
previously_executed_context_which_yielded_to_resume_the_current_context: SavedContextWrapper,
data_passed_from_previously_executed_context: DataToTransfer,
}
impl Transfer
{
#[inline(always)]
pub fn new(stack: &impl Stack, context_entry_point_function_pointer: ContextEntryPointFunctionPointer) -> Self
{
Self
{
previously_executed_context_which_yielded_to_resume_the_current_context: SavedContextWrapper::initialize(stack, context_entry_point_function_pointer),
data_passed_from_previously_executed_context: unsafe { uninitialized() },
}
}
#[inline(always)]
pub fn resume<TD: TransferableData>(&mut self, data_to_transfer: TD)
{
*self = self.previously_executed_context_which_yielded_to_resume_the_current_context.resume(data_to_transfer.into_usize())
}
#[inline(always)]
pub fn transferred_data<TD: TransferableData>(&self) -> TD
{
TD::from_usize(self.data_passed_from_previously_executed_context)
}
}