Trait jlrs::memory::traits::scope::ScopeExt[][src]

pub trait ScopeExt<'outer, 'scope, 'frame, 'data, F: Frame<'frame>>: Scope<'scope, 'frame, 'data, F> where
    Self: 'outer, 
{ fn scope<T, G>(self, func: G) -> JlrsResult<T>
    where
        T: 'outer,
        G: FnOnce(&mut GcFrame<'inner, F::Mode>) -> JlrsResult<T>
;
fn scope_with_slots<T, G>(self, capacity: usize, func: G) -> JlrsResult<T>
    where
        T: 'outer,
        G: FnOnce(&mut GcFrame<'inner, F::Mode>) -> JlrsResult<T>
; }

Provides scope and scope_with_slots methods to mutable references of types that implement Frame.

Required methods

fn scope<T, G>(self, func: G) -> JlrsResult<T> where
    T: 'outer,
    G: FnOnce(&mut GcFrame<'inner, F::Mode>) -> JlrsResult<T>, 
[src]

Create a GcFrame and call the given closure with it. Returns the result of this closure.

Example:

  julia.scope(|global, frame| {
      let sum = frame.scope(|frame| {
          let v1 = Value::new(&mut *frame, 1usize)?;
          let v2 = Value::new(&mut *frame, 2usize)?;

          Module::base(global)
              .function("+")?
              .call2(&mut *frame, v1, v2)?
              .unwrap()
              .cast::<usize>()
      })?;

      assert_eq!(sum, 3);
      Ok(())
  }).unwrap();

fn scope_with_slots<T, G>(self, capacity: usize, func: G) -> JlrsResult<T> where
    T: 'outer,
    G: FnOnce(&mut GcFrame<'inner, F::Mode>) -> JlrsResult<T>, 
[src]

Create a GcFrame with capacity slots and call the given closure with it. Returns the result of this closure.

Example:

  julia.scope(|global, frame| {
      let sum = frame.scope_with_slots(3, |frame| {
          let v1 = Value::new(&mut *frame, 1usize)?;
          let v2 = Value::new(&mut *frame, 2usize)?;

          Module::base(global)
              .function("+")?
              .call2(&mut *frame, v1, v2)?
              .unwrap()
              .cast::<usize>()
      })?;

      assert_eq!(sum, 3);
      Ok(())
  }).unwrap();
Loading content...

Implementations on Foreign Types

impl<'outer, 'frame, 'data, F: Frame<'frame>> ScopeExt<'outer, 'frame, 'frame, 'data, F> for &'outer mut F[src]

Loading content...

Implementors

Loading content...