From efbf91338082513cdbf1fb15eddb162ebf214433 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Mon, 26 Feb 2024 02:45:51 -0700 Subject: [PATCH] Move error parsing code into launch_unchecked --- ctru-rs/src/applets/error.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ctru-rs/src/applets/error.rs b/ctru-rs/src/applets/error.rs index 9bc66da..6450a41 100644 --- a/ctru-rs/src/applets/error.rs +++ b/ctru-rs/src/applets/error.rs @@ -1,6 +1,7 @@ //! Error applet //! //! This applet displays error text as a pop-up message on the lower screen. + use crate::services::{apt::Apt, gfx::Gfx}; use ctru_sys::errorConf; @@ -66,7 +67,16 @@ impl PopUp { /// Launches the error applet. #[doc(alias = "errorDisp")] pub fn launch(&mut self, _apt: &Apt, _gfx: &Gfx) -> Result<(), Error> { - unsafe { ctru_sys::errorDisp(self.state.as_mut()) } + unsafe { self.launch_unchecked() } + } + + /// Launches the error applet without requiring an [`Apt`] or [`Gfx`] handle. + /// + /// # Safety + /// + /// Causes undefined behavior if the aforementioned services are not actually active when the applet launches. + unsafe fn launch_unchecked(&mut self) -> Result<(), Error> { + unsafe { ctru_sys::errorDisp(self.state.as_mut()) }; match self.state.returnCode { ctru_sys::ERROR_NONE | ctru_sys::ERROR_SUCCESS => Ok(()), @@ -77,15 +87,6 @@ impl PopUp { _ => Err(Error::Unknown), } } - - /// Launches the error applet without requiring an [`Apt`] or [`Gfx`] handle. - /// - /// # Safety - /// - /// Causes undefined behavior if the aforementioned services are not actually active when the applet launches. - unsafe fn launch_unchecked(&mut self) { - unsafe { ctru_sys::errorDisp(self.state.as_mut()) }; - } } /// Sets a custom [panic hook](https://doc.rust-lang.org/std/panic/fn.set_hook.html) that uses the error applet to display panic messages. @@ -123,7 +124,7 @@ pub fn set_panic_hook(call_old_hook: bool) { popup.set_text(&payload); unsafe { - popup.launch_unchecked(); + let _ = popup.launch_unchecked(); } } else { old_hook(panic_info);