Struct context::context::Context [] [src]

#[repr(C)]
pub struct Context(_);

A Context stores a ContextFn's state of execution, for it to be resumed later.

If we have 2 or more Context instances, we can thus easily "freeze" the current state of execution and explicitely switch to another Context. This Context is then resumed exactly where it left of and can in turn "freeze" and switch to another Context.

Examples

See examples/basic.rs

Methods

impl Context
[src]

[src]

Creates a new Context prepared to execute f at the beginning of stack.

f is not executed until the first call to resume().

It is unsafe because it only takes a reference of Stack. You have to make sure the Stack lives longer than the generated Context.

[src]

Yields the execution to another Context.

The exact behaviour of this method is implementation defined, but the general mechanism is: The current state of execution is preserved somewhere and the previously saved state in the Context pointed to by self is restored and executed next.

This behaviour is similiar in spirit to regular function calls with the difference that the call to resume() only returns when someone resumes the caller in turn.

The returned Transfer struct contains the previously active Context and the data argument used to resume the current one.

It is unsafe because it is your responsibility to make sure that all data that constructed in this context have to be dropped properly when the last context is dropped.

[src]

Yields the execution to another Context and executes a function "ontop" of it's stack.

This method identical to resume() with a minor difference:

The argument f is executed right after the targeted Context, pointed to by self, is woken up, but before it returns from it's call to resume(). f now gets passed the Transfer struct which would normally be returned by resume() and is allowed to inspect and modify it. The Transfer struct f returns is then finally the one returned by resume() in the targeted Context.

This behaviour can be used to either execute additional code or map the Transfer struct to another one before it's returned, without the targeted Context giving it's consent. For instance it can be used to unwind the stack of an unfinished Context, by calling this method with a function that panics, or to deallocate the own stack, by deferring the actual deallocation until we jumped to another, safe Context.

It is unsafe because it is your responsibility to make sure that all data that constructed in this context have to be dropped properly when the last context is dropped.

Trait Implementations

impl Debug for Context
[src]

[src]

Formats the value using the given formatter.