pub unsafe fn with_ffi_boundary<F, T>(&mut self, func: F) -> Result<T, InterpreterExtractError>
    where
        F: FnOnce(*mut sys::mrb_state) -> T,
    {
        if let Some(state) = self.state.take() {
            // Ensure we don't create multiple mutable references by moving the
            // `mrb` out of the `Artichoke` and converting to a raw pointer.
            //
            // Safety:
            //
            // 1. Extract a `*mut sys::mrb_state` pointer from the `NonNull` mrb
            //    field.
            // 2. Function safety conditions declare that `Artichoke` is not
            //    accessed inside the closure.
            // 3. Rust borrowing rules enforce that `Artichoke` is not accessed
            //    inside the closure.
            // 4. This function moves the `State` into the `mrb`.
            // 5. If `mrb` re-enters `Artichoke` via trampoline, a new
            //    `Artichoke` is made by moving the `State` out of the `mrb`.
            // 6. The `Artichoke` in the FFI entry point is wrapped in a `Guard`.
            // 7. On drop, `Guard` moves the `State` back into the `mrb`.
            // 8. On return from `mrb`, here, extract the `State` which should be
            //    moved back into the `mrb`.
            // 9. Replace `self` with the new interpreter.

            // Step 1
            let mrb = self.mrb.as_ptr();

            // Step 4
            (*mrb).ud = Box::into_raw(state).cast::<c_void>();

            // Steps 5-7
            let result = func(mrb);

            // Step 8
            let extracted = ffi::from_user_data(mrb)?;

            // Step 9
            self.state = extracted.state;
            Ok(result)
        } else {
            Err(InterpreterExtractError::new())
        }
    }
/// Execute a a closure by moving the [`State`] into the `mrb` instance.
///
/// This method prepares this interpreter to cross an FFI boundary. When the
/// Artichoke implementation calls mruby FFI functions, the `State` must be
/// moved into the [`sys::mrb_state`] userdata pointer.
///
/// # Safety
///
/// This method moves the `State` out of this instance into the `mrb`
/// instance. During this function's execution, this instance may be
/// partially initialized.
///
/// This function is only safe to call if the closure only calls FFI
/// functions that use a raw `*mut sys::mrb_state`.
Execute a a closure by moving the [`State`] into the `mrb` instance.
This method prepares this interpreter to cross an FFI boundary. When the
Artichoke implementation calls mruby FFI functions, the `State` must be
moved into the [`sys::mrb_state`] userdata pointer.
Execute a a closure by moving the [ ` State ` ] into the ` mrb ` instance . This method prepares this interpreter to cross an FFI boundary . When the Artichoke implementation calls mruby FFI functions the ` State ` must be moved into the [ ` sys :: mrb_state ` ] userdata pointer .
pub unsafe fn with_ffi_boundary<F, T>(&mut self, func: F) -> Result<T, InterpreterExtractError>
    where
        F: FnOnce(*mut sys::mrb_state) -> T,
    {
        if let Some(state) = self.state.take() {
            // Ensure we don't create multiple mutable references by moving the
            // `mrb` out of the `Artichoke` and converting to a raw pointer.
            //
            // Safety:
            //
            // 1. Extract a `*mut sys::mrb_state` pointer from the `NonNull` mrb
            //    field.
            // 2. Function safety conditions declare that `Artichoke` is not
            //    accessed inside the closure.
            // 3. Rust borrowing rules enforce that `Artichoke` is not accessed
            //    inside the closure.
            // 4. This function moves the `State` into the `mrb`.
            // 5. If `mrb` re-enters `Artichoke` via trampoline, a new
            //    `Artichoke` is made by moving the `State` out of the `mrb`.
            // 6. The `Artichoke` in the FFI entry point is wrapped in a `Guard`.
            // 7. On drop, `Guard` moves the `State` back into the `mrb`.
            // 8. On return from `mrb`, here, extract the `State` which should be
            //    moved back into the `mrb`.
            // 9. Replace `self` with the new interpreter.
            // Step 1
            let mrb = self.mrb.as_ptr();
            // Step 4
            (*mrb).ud = Box::into_raw(state).cast::<c_void>();
            // Steps 5-7
            let result = func(mrb);
            // Step 8
            let extracted = ffi::from_user_data(mrb)?;
            // Step 9
            self.state = extracted.state;
            Ok(result)
        } else {
            Err(InterpreterExtractError::new())
        }
    }
pub unsafe fn with_ffi_boundary < F , T > ( & mut self , func : F ) -> Result < T , InterpreterExtractError > where F : FnOnce ( * mut sys :: mrb_state ) -> T , { if let Some ( state ) = self . state . take ( ) { // Ensure we don't create multiple mutable references by moving the // `mrb` out of the `Artichoke` and converting to a raw pointer. // // Safety: // // 1. Extract a `*mut sys::mrb_state` pointer from the `NonNull` mrb //    field. // 2. Function safety conditions declare that `Artichoke` is not //    accessed inside the closure. // 3. Rust borrowing rules enforce that `Artichoke` is not accessed //    inside the closure. // 4. This function moves the `State` into the `mrb`. // 5. If `mrb` re-enters `Artichoke` via trampoline, a new //    `Artichoke` is made by moving the `State` out of the `mrb`. // 6. The `Artichoke` in the FFI entry point is wrapped in a `Guard`. // 7. On drop, `Guard` moves the `State` back into the `mrb`. // 8. On return from `mrb`, here, extract the `State` which should be //    moved back into the `mrb`. // 9. Replace `self` with the new interpreter. // Step 1 let mrb = self . mrb . as_ptr ( ) ; // Step 4 ( * mrb ) . ud = Box :: into_raw ( state ) . cast :: < c_void > ( ) ; // Steps 5-7 let result = func ( mrb ) ; // Step 8 let extracted = ffi :: from_user_data ( mrb ) ? ; // Step 9 self . state = extracted . state ; Ok ( result ) } else { Err ( InterpreterExtractError :: new ( ) ) } }
Execute a a closure by moving the [`State`] into the `mrb` instance.
Execute a a closure by moving the [ ` State ` ] into the ` mrb ` instance .
&mut self
func
F
safety
This method moves the `State` out of this instance into the `mrb`
instance. During this function's execution, this instance may be
partially initialized.

This function is only safe to call if the closure only calls FFI
functions that use a raw `*mut sys::mrb_state`.
This method moves the ` State ` out of this instance into the ` mrb ` instance . During this function ' s execution this instance may be partially initialized . This function is only safe to call if the closure only calls FFI functions that use a raw ` * mut sys :: mrb_state ` .