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

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

Functionality shared by StaticFrame and DynamicFrame.

Frames use two lifetimes, 'base and 'frame. The first is used to ensure global Julia values, like Modules and functions accessed through modules, can be used freely across frames, but can't be returned from the frame created through Julia::frame or Julia::dynamic_frame. Other values get the 'frame lifetime which ensures those values can live as long as their frames.

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 call the function through Value::call_output or one of the other call*_output methods. 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<T, F: FnOnce(&mut StaticFrame<'base, '_>) -> JlrsResult<T>>(
    &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<T, F: FnOnce(&mut DynamicFrame<'base, '_>) -> JlrsResult<T>>(
    &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<'base: 'frame, 'frame> Frame<'base, 'frame> for DynamicFrame<'base, 'frame>[src]

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

Loading content...