From 144658345cbc612081cf954de88087e23f18b295 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Sat, 17 Feb 2024 11:30:09 -0700 Subject: [PATCH] MessageCallbackData doesn't need to be a struct member --- ctru-rs/src/applets/swkbd.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 6290e07..a1c5f7e 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -26,7 +26,6 @@ type CallbackFunction = dyn Fn(&CStr) -> (CallbackResult, Option); pub struct SoftwareKeyboard { state: Box, callback: Option>, - callback_data: MessageCallbackData, error_message: Option, initial_text: Option, } @@ -220,15 +219,6 @@ struct MessageCallbackData { swkbd_shared_mem_ptr: *mut libc::c_void, } -impl MessageCallbackData { - fn new() -> Self { - Self { - extra: std::ptr::null_mut(), - swkbd_shared_mem_ptr: std::ptr::null_mut(), - } - } -} - impl SoftwareKeyboard { /// Initialize a new configuration for the Software Keyboard applet depending on how many "exit" buttons are available to the user (1, 2 or 3). /// @@ -257,7 +247,6 @@ impl SoftwareKeyboard { callback: None, error_message: None, initial_text: None, - callback_data: MessageCallbackData::new(), } } } @@ -788,13 +777,15 @@ impl SoftwareKeyboard { unsafe { swkbd.__bindgen_anon_1.reserved.fill(0); - if extra.callback.is_some() { - self.callback_data.extra = std::ptr::addr_of_mut!(extra); - self.callback_data.swkbd_shared_mem_ptr = swkbd_shared_mem_ptr; + let mut callback_data = MessageCallbackData { + extra: std::ptr::addr_of_mut!(extra), + swkbd_shared_mem_ptr, + }; + if extra.callback.is_some() { aptSetMessageCallback( Some(Self::swkbd_message_callback), - std::ptr::addr_of_mut!(self.callback_data).cast(), + std::ptr::addr_of_mut!(callback_data).cast(), ); }