ScopedCoroutineRef

Struct ScopedCoroutineRef 

Source
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>

Source

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.

Source

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.

Source

pub fn started(&self) -> bool

Returns whether this coroutine has been resumed at least once.

Source

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.

Source

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.

Source

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 ForcedUnwind panic that is used internally was caught and not rethrown.
  • This crate was compiled without the unwind feature and the coroutine is currently suspended in the yielder (started && !done).
Source

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.

Auto Trait Implementations§

§

impl<'a, Input, Yield, Return, Stack> Freeze for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>

§

impl<'a, Input, Yield, Return, Stack> RefUnwindSafe for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>
where Stack: RefUnwindSafe,

§

impl<'a, Input, Yield, Return, Stack> !Send for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>

§

impl<'a, Input, Yield, Return, Stack> Sync for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>
where Stack: Sync,

§

impl<'a, Input, Yield, Return, Stack> Unpin for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>

§

impl<'a, Input, Yield, Return, Stack> !UnwindSafe for ScopedCoroutineRef<'a, Input, Yield, Return, Stack>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.