[][src]Trait jlrs::traits::Frame

pub trait Frame<'frame>: Frame<'frame> {
    fn frame<'nested, T, F: FnOnce(&mut StaticFrame<'nested, Self::U>) -> JlrsResult<T>>(
        &'nested mut self,
        capacity: usize,
        func: F
    ) -> JlrsResult<T>;
fn dynamic_frame<'nested, T, F: FnOnce(&mut DynamicFrame<'nested, Self::U>) -> JlrsResult<T>>(
        &'nested mut self,
        func: F
    ) -> JlrsResult<T>;
fn output(&mut self) -> JlrsResult<Output<'frame>>;
fn size(&self) -> usize; }

Functionality shared by StaticFrame and DynamicFrame. These structs let you protect data from garbage collection. The lifetime of a frame is assigned to the values and outputs that are created using that frame. After a frame is dropped, these items are no longer protected and cannot be used.

If you need the result of a function call to be valid outside the frame where it is called, you can call Frame::output to create an Output and use Value::with_output to use the output to protect the value rather than the current frame. The result will share the output's lifetime so it can be used until the output's frame goes out of scope.

Required methods

fn frame<'nested, T, F: FnOnce(&mut StaticFrame<'nested, Self::U>) -> JlrsResult<T>>(
    &'nested mut self,
    capacity: usize,
    func: F
) -> JlrsResult<T>

Create a StaticFrame that can hold capacity values, and call the given closure. Returns the result of this closure, or an error if the new frame can't be created because there's not enough space on the GC stack. The number of required slots on the stack is capacity + 2.

Returns an error if there is not enough space on the stack.

fn dynamic_frame<'nested, T, F: FnOnce(&mut DynamicFrame<'nested, Self::U>) -> JlrsResult<T>>(
    &'nested mut self,
    func: F
) -> JlrsResult<T>

Create a DynamicFrame and call the given closure. Returns the result of this closure, or an error if the new frame can't be created because the stack is too small. The number of required slots on the stack is 2.

Returns an error if there is not enough space on the stack.

fn output(&mut self) -> JlrsResult<Output<'frame>>

Returns a new Output, this takes one slot on the GC stack. A function that uses this output will not use a slot on the GC stack, but the one associated with this output. This extends the lifetime of that value to be valid until the frame that created the output goes out of scope.

Returns an error if there is not enough space on the stack.

fn size(&self) -> usize

Returns the number of values belonging to this frame.

Loading content...

Implementors

impl<'frame> Frame<'frame> for AsyncFrame<'frame>[src]

impl<'frame> Frame<'frame> for NullFrame<'frame>[src]

impl<'frame, M: Mode> Frame<'frame> for DynamicFrame<'frame, M>[src]

impl<'frame, M: Mode> Frame<'frame> for StaticFrame<'frame, M>[src]

Loading content...