Skip to content

Commit

Permalink
swkbd_input_text is no longer an unsafe fn
Browse files Browse the repository at this point in the history
  • Loading branch information
FenrirWolf committed Mar 11, 2024
1 parent e5581b4 commit 454028f
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions ctru-rs/src/applets/swkbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,15 @@ impl SoftwareKeyboard {
/// # }
/// ```
#[doc(alias = "swkbdInputText")]
pub fn launch(&mut self, _apt: &Apt, _gfx: &Gfx) -> Result<(String, Button), Error> {
pub fn launch(&mut self, apt: &Apt, gfx: &Gfx) -> Result<(String, Button), Error> {
let mut output = String::new();

unsafe {
match self.swkbd_input_text(&mut output) {
ctru_sys::SWKBD_BUTTON_NONE => Err(self.state.result.into()),
ctru_sys::SWKBD_BUTTON_LEFT => Ok((output, Button::Left)),
ctru_sys::SWKBD_BUTTON_MIDDLE => Ok((output, Button::Middle)),
ctru_sys::SWKBD_BUTTON_RIGHT => Ok((output, Button::Right)),
_ => unreachable!(),
}
match self.swkbd_input_text(&mut output, &apt, &gfx) {

Check warning on line 275 in ctru-rs/src/applets/swkbd.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2024-02-18)

this expression creates a reference which is immediately dereferenced by the compiler

Check warning on line 275 in ctru-rs/src/applets/swkbd.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2024-02-18)

this expression creates a reference which is immediately dereferenced by the compiler
ctru_sys::SWKBD_BUTTON_NONE => Err(self.state.result.into()),
ctru_sys::SWKBD_BUTTON_LEFT => Ok((output, Button::Left)),
ctru_sys::SWKBD_BUTTON_MIDDLE => Ok((output, Button::Middle)),
ctru_sys::SWKBD_BUTTON_RIGHT => Ok((output, Button::Right)),
_ => unreachable!(),
}
}

Expand Down Expand Up @@ -585,13 +583,9 @@ impl SoftwareKeyboard {
self.state.valid_input = ValidInput::FixedLen.into();
}

/// A reimplementation of `swkbdInputText` from `libctru/source/applets/swkbd.c`. Allows us to fix various
/// API nits and get rid of awkward type conversions when interacting with the Software Keyboard.
///
/// # Safety
///
/// The [`Apt`] and [`Gfx`] services must be active when this function is called.
unsafe fn swkbd_input_text(&mut self, output: &mut String) -> SwkbdButton {
// A reimplementation of `swkbdInputText` from `libctru/source/applets/swkbd.c`. Allows us to fix various
// API nits and get rid of awkward type conversions when interacting with the Software Keyboard.
fn swkbd_input_text(&mut self, output: &mut String, _apt: &Apt, _gfx: &Gfx) -> SwkbdButton {
use ctru_sys::{
MEMPERM_READ, MEMPERM_WRITE, R_FAILED, SWKBD_BUTTON_LEFT, SWKBD_BUTTON_MIDDLE,
SWKBD_BUTTON_NONE, SWKBD_BUTTON_RIGHT, SWKBD_D0_CLICK, SWKBD_D1_CLICK0,
Expand Down

0 comments on commit 454028f

Please sign in to comment.