diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index ad39c335..a3e6ec81 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -5,6 +5,8 @@ use ctru::applets::swkbd::{Button, CallbackResult, SoftwareKeyboard}; use ctru::prelude::*; +use std::ffi::CString; + fn main() { let apt = Apt::new().unwrap(); let mut hid = Hid::new().unwrap(); @@ -23,7 +25,7 @@ fn main() { if text.contains("boo") { return ( CallbackResult::Retry, - Some(String::from("Ah, you scared me!")), + Some(CString::new("Ah, you scared me!").unwrap()), ); } diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 0486a5a9..8f7795e3 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -14,7 +14,7 @@ use std::fmt::Display; use std::iter::once; use std::str; -type CallbackFunction = dyn Fn(&str) -> (CallbackResult, Option); +type CallbackFunction = dyn Fn(&str) -> (CallbackResult, Option); /// Configuration structure to setup the Software Keyboard applet. #[doc(alias = "SwkbdState")] @@ -399,6 +399,7 @@ impl SoftwareKeyboard { /// # fn main() { /// # /// use std::borrow::Cow; + /// use std::ffi::CString; /// use ctru::applets::swkbd::{SoftwareKeyboard, CallbackResult}; /// /// let mut keyboard = SoftwareKeyboard::default(); @@ -407,7 +408,7 @@ impl SoftwareKeyboard { /// if text.contains("boo") { /// return ( /// CallbackResult::Retry, - /// Some(String::from("Ah, you scared me!")), + /// Some(CString::new("Ah, you scared me!").unwrap()), /// ); /// } /// @@ -442,8 +443,6 @@ impl SoftwareKeyboard { // Due to how `libctru` operates, the user is expected to keep the error message alive until // the end of the Software Keyboard prompt. We ensure that happens by saving it within the configuration. if let Some(error_message) = error_message { - let error_message = CString::from_vec_unchecked(error_message.into_bytes()); - *pp_message = error_message.as_ptr(); this.error_message = Some(error_message);