pub struct ScopedCoroutineRef<'a, Input, Yield, Return, Stack: Stack> { /* private fields */ }Expand description
Reference to a coroutine within a scope created by
ScopedCoroutine::scope.
Note that, unlike normal mutable references, Rust will not automatically
re-borrow this type so you may need to use the
ScopedCoroutineRef::as_mut method when invoking methods that take a
mutable reference.
Implementations§
Source§impl<Input, Yield, Return, Stack: Stack> ScopedCoroutineRef<'_, Input, Yield, Return, Stack>
impl<Input, Yield, Return, Stack: Stack> ScopedCoroutineRef<'_, Input, Yield, Return, Stack>
Sourcepub fn as_mut(&mut self) -> ScopedCoroutineRef<'_, Input, Yield, Return, Stack>
pub fn as_mut(&mut self) -> ScopedCoroutineRef<'_, Input, Yield, Return, Stack>
Reborrows the ScopedCoroutineRef.
This is useful when the reference needs to be used multiple times.
This is necessary before Rust only supports automatic reborrowing for plain mutable references.
Sourcepub fn resume(&mut self, val: Input) -> CoroutineResult<Yield, Return>
pub fn resume(&mut self, val: Input) -> CoroutineResult<Yield, Return>
Resumes execution of this coroutine.
This function will transfer execution to the coroutine and resume from where it last left off.
If the coroutine calls Yielder::suspend then this function returns
CoroutineResult::Yield with the value passed to suspend.
If the coroutine returns then this function returns
CoroutineResult::Return with the return value of the coroutine.
§Panics
Panics if the coroutine has already finished executing.
If the coroutine itself panics during execution then the panic will be propagated to this caller.
Sourcepub fn done(&self) -> bool
pub fn done(&self) -> bool
Returns whether this coroutine has finished executing.
A coroutine that has returned from its initial function can no longer be resumed.
Sourcepub unsafe fn force_reset(&mut self)
pub unsafe fn force_reset(&mut self)
Forcibly marks the coroutine as having completed, even if it is currently suspended in the middle of a function.
§Safety
This is equivalent to a longjmp all the way back to the initial
function of the coroutine, so the same rules apply.
This can only be done safely if there are no objects currently on the
coroutine’s stack that need to execute Drop code.
Sourcepub fn force_unwind(&mut self)
pub fn force_unwind(&mut self)
Unwinds the coroutine stack, dropping any live objects that are currently on the stack. This is automatically called when the coroutine is dropped.
If the coroutine has already completed then this function is a no-op.
If the coroutine is currently suspended on a Yielder::suspend call
then unwinding it requires the unwind feature to be enabled and
for the crate to be compiled with -C panic=unwind.
§Panics
This function panics if the coroutine could not be fully unwound. This can happen for one of two reasons:
- The
ForcedUnwindpanic that is used internally was caught and not rethrown. - This crate was compiled without the
unwindfeature and the coroutine is currently suspended in the yielder (started && !done).
Sourcepub fn trap_handler(&self) -> CoroutineTrapHandler<Return>
pub fn trap_handler(&self) -> CoroutineTrapHandler<Return>
Returns a CoroutineTrapHandler which can be used to handle traps that
occur inside the coroutine. Examples of traps that can be handled are
invalid memory accesses and stack overflows.
The returned CoroutineTrapHandler can be used in a trap handler to
force the trapping coroutine to return with a specific value, after
which is it considered to have completed and can no longer be resumed.
Needless to say, this is extremely unsafe and must be used with extreme
care. See CoroutineTrapHandler::setup_trap_handler for the exact
safety requirements.