fn try_user_callback_transition()

in src/platform_impl/ios/app_state.rs [311:381]


    fn try_user_callback_transition(&mut self) -> UserCallbackTransitionResult<'_> {
        // If we're not able to process an event due to recursion or `Init` not having been sent out
        // yet, then queue the events up.
        match self.state_mut() {
            &mut AppStateImpl::Launching {
                ref mut queued_events,
                ..
            }
            | &mut AppStateImpl::NotLaunched {
                ref mut queued_events,
                ..
            }
            | &mut AppStateImpl::InUserCallback {
                ref mut queued_events,
                ..
            } => {
                // A lifetime cast: early returns are not currently handled well with NLL, but
                // polonius handles them well. This transmute is a safe workaround.
                return unsafe {
                    mem::transmute::<
                        UserCallbackTransitionResult<'_>,
                        UserCallbackTransitionResult<'_>,
                    >(UserCallbackTransitionResult::ReentrancyPrevented {
                        queued_events,
                    })
                };
            }

            &mut AppStateImpl::ProcessingEvents { .. }
            | &mut AppStateImpl::ProcessingRedraws { .. } => {}

            s @ &mut AppStateImpl::PollFinished { .. }
            | s @ &mut AppStateImpl::Waiting { .. }
            | s @ &mut AppStateImpl::Terminated => {
                bug!("unexpected attempted to process an event {:?}", s)
            }
        }

        let (event_handler, queued_gpu_redraws, active_control_flow, processing_redraws) =
            match self.take_state() {
                AppStateImpl::Launching { .. }
                | AppStateImpl::NotLaunched { .. }
                | AppStateImpl::InUserCallback { .. } => unreachable!(),
                AppStateImpl::ProcessingEvents {
                    event_handler,
                    queued_gpu_redraws,
                    active_control_flow,
                } => (
                    event_handler,
                    queued_gpu_redraws,
                    active_control_flow,
                    false,
                ),
                AppStateImpl::ProcessingRedraws {
                    event_handler,
                    active_control_flow,
                } => (event_handler, Default::default(), active_control_flow, true),
                AppStateImpl::PollFinished { .. }
                | AppStateImpl::Waiting { .. }
                | AppStateImpl::Terminated => unreachable!(),
            };
        self.set_state(AppStateImpl::InUserCallback {
            queued_events: Vec::new(),
            queued_gpu_redraws,
        });
        UserCallbackTransitionResult::Success {
            event_handler,
            active_control_flow,
            processing_redraws,
        }
    }