Trait jlrs::memory::traits::scope::Scope [−][src]
pub trait Scope<'scope, 'frame, 'data, F: Frame<'frame>>: Sized + Scope<'scope, 'frame, 'data, F> { fn value_scope<G>(self, func: G) -> JlrsResult<Self::Value>
where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>; fn result_scope<G>(self, func: G) -> JlrsResult<Self::JuliaResult>
where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>; fn value_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value>
where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>; fn result_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult>
where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>; fn global(&self) -> Global<'scope> { ... } }
This trait is used to root raw Julia values in the current or an earlier frame. Scopes and
frames are very similar, in fact, all mutable references to frames are scopes: one that
targets that frame. The other implementor of this trait, OutputScope
, targets an earlier
frame. In addition to rooting values, this trait provides several methods that create a new
frame; if the scope is a frame, the frame’s implementation of that method is called. If the
scope is an OutputScope
, the result is rooted the frame targeted by that scope.
Required methods
fn value_scope<G>(self, func: G) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
Create a new GcFrame
that can be used to root capacity
values, an Output
for the
current scope, and use them to call the inner closure. The final result is not rooted in
this newly created frame, but the current frame. The final result must not be the result
of a function call, use Scope::result_scope
for that purpose instead. If the current
scope is a mutable reference to a frame, calling this method will require one slot of the
current frame.
Example:
julia.scope(|global, frame| { let _nt = frame.value_scope(|output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let output = output.into_scope(frame); named_tuple!(output, "a" => v1, "b" => v2) })?; Ok(()) }).unwrap();
fn result_scope<G>(self, func: G) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
Create a new GcFrame
that can be used to root capacity
values, an Output
for the
current scope, and use them to call the inner closure. The final result is not rooted in
this newly created frame, but the current frame. The final result must be the result of a
function call, if you want to create a new value use Scope::value_scope
instead. If
the current scope is a mutable reference to a frame, calling this method will require one
slot of the current frame.
Example:
julia.scope(|global, frame| { let sum = frame.result_scope(|output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let add = Module::base(global).function("+")?; let output = output.into_scope(frame); add.call2(output, v1, v2) })?.unwrap().cast::<usize>()?; assert_eq!(sum, 3); Ok(()) }).unwrap();
fn value_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
Create a new GcFrame
that can be used to root capacity
values, an Output
for the
current scope, and use them to call the inner closure. The final result is not rooted in
this newly created frame, but the current frame. The final result must not be the result
of a function call, use Scope::result_scope
for that purpose instead. If the current
scope is a mutable reference to a frame, calling this method will require one slot of the
current frame.
Example:
julia.scope(|global, frame| { let _nt = frame.value_scope(|output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let output = output.into_scope(frame); named_tuple!(output, "a" => v1, "b" => v2) })?; Ok(()) }).unwrap();
fn result_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
Create a new GcFrame
that can be used to root capacity
values, an Output
for the
current scope, and use them to call the inner closure. The final result is not rooted in
this newly created frame, but the current frame. The final result must be the result of a
function call, if you want to create a new value use Scope::value_scope
instead. If
the current scope is a mutable reference to a frame, calling this method will require one
slot of the current frame.
Example:
julia.scope(|global, frame| { let sum = frame.result_scope(|output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let add = Module::base(global).function("+")?; let output = output.into_scope(frame); add.call2(output, v1, v2) })?.unwrap().cast::<usize>()?; assert_eq!(sum, 3); Ok(()) }).unwrap();
Provided methods
Loading content...Implementations on Foreign Types
impl<'frame, 'data, F: Frame<'frame>> Scope<'frame, 'frame, 'data, F> for &mut F
[src]
impl<'frame, 'data, F: Frame<'frame>> Scope<'frame, 'frame, 'data, F> for &mut F
[src]fn value_scope<G>(self, func: G) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'frame, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'frame, 'data, 'inner>>,
Creates a GcFrame
and calls the given closure with it. Returns the result of this
closure.
Example:
julia.scope(|_global, frame| { let _nt = frame.value_scope(|output, frame| { let i = Value::new(&mut *frame, 2u64)?; let j = Value::new(&mut *frame, 1u32)?; let output = output.into_scope(frame); named_tuple!(output, "i" => i, "j" => j) })?; Ok(()) }).unwrap();
fn result_scope<G>(self, func: G) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'frame, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'frame, 'data, 'inner>>,
Creates a GcFrame
and calls the given closure with it. Returns the result of this
closure.
Example:
julia.scope(|global, frame| { let sum = frame.result_scope(|output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let output = output.into_scope(frame); Module::base(global) .function("+")? .call2(output, v1, v2) })?.unwrap() .cast::<usize>()?; assert_eq!(sum, 3); Ok(()) }).unwrap();
fn value_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'frame, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'frame, 'data, 'inner>>,
Creates a GcFrame
and calls the given closure with it. Returns the result of this
closure.
Example:
julia.scope(|_global, frame| { let _nt = frame.value_scope_with_slots(2, |output, frame| { let i = Value::new(&mut *frame, 2u64)?; let j = Value::new(&mut *frame, 1u32)?; let output = output.into_scope(frame); named_tuple!(output, "i" => i, "j" => j) })?; Ok(()) }).unwrap();
fn result_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'frame, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'frame>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'frame, 'data, 'inner>>,
Creates a GcFrame
with capacity
preallocated slots and calls the given closure with
it. Returns the result of this closure.
Example:
julia.scope(|global, frame| { let sum = frame.result_scope_with_slots(2, |output, frame| { let v1 = Value::new(&mut *frame, 1usize)?; let v2 = Value::new(&mut *frame, 2usize)?; let output = output.into_scope(frame); Module::base(global) .function("+")? .call2(output, v1, v2) })?.unwrap() .cast::<usize>()?; assert_eq!(sum, 3); Ok(()) }).unwrap();
Implementors
impl<'scope, 'frame, 'data, 'borrow, F: Frame<'frame>> Scope<'scope, 'frame, 'data, F> for OutputScope<'scope, 'frame, 'borrow, F>
[src]
impl<'scope, 'frame, 'data, 'borrow, F: Frame<'frame>> Scope<'scope, 'frame, 'data, F> for OutputScope<'scope, 'frame, 'borrow, F>
[src]fn value_scope<G>(self, func: G) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
fn result_scope<G>(self, func: G) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
[src]
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
fn value_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::Value> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedValue<'scope, 'data, 'inner>>,
fn result_scope_with_slots<G>(
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,
[src]
self,
capacity: usize,
func: G
) -> JlrsResult<Self::JuliaResult> where
G: for<'nested, 'inner> FnOnce(Output<'scope>, &'inner mut GcFrame<'nested, F::Mode>) -> JlrsResult<UnrootedResult<'scope, 'data, 'inner>>,