Browse Source

Return Cow<str> from filter callback

pull/163/head
Fenrir 10 months ago
parent
commit
3d59bdd2b7
  1. 5
      ctru-rs/examples/software-keyboard.rs
  2. 9
      ctru-rs/src/applets/swkbd.rs

5
ctru-rs/examples/software-keyboard.rs

@ -21,10 +21,7 @@ fn main() {
// with custom error messages when the input is incorrect. // with custom error messages when the input is incorrect.
keyboard.set_filter_callback(Some(Box::new(|str| { keyboard.set_filter_callback(Some(Box::new(|str| {
if str.contains("boo") { if str.contains("boo") {
return ( return (CallbackResult::Retry, Some("Ah, you scared me!".into()));
CallbackResult::Retry,
Some(String::from("Ah, you scared me!")),
);
} }
(CallbackResult::Ok, None) (CallbackResult::Ok, None)

9
ctru-rs/src/applets/swkbd.rs

@ -12,12 +12,13 @@ use ctru_sys::{
use bitflags::bitflags; use bitflags::bitflags;
use std::borrow::Cow;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::fmt::Display; use std::fmt::Display;
use std::iter::once; use std::iter::once;
use std::str; use std::str;
type CallbackFunction = dyn Fn(&str) -> (CallbackResult, Option<String>); type CallbackFunction = dyn Fn(&str) -> (CallbackResult, Option<Cow<str>>);
/// Configuration structure to setup the Software Keyboard applet. /// Configuration structure to setup the Software Keyboard applet.
#[doc(alias = "SwkbdState")] #[doc(alias = "SwkbdState")]
@ -342,17 +343,13 @@ impl SoftwareKeyboard {
/// # fn main() { /// # fn main() {
/// # /// #
/// use std::borrow::Cow; /// use std::borrow::Cow;
/// use std::ffi::CString;
/// use ctru::applets::swkbd::{SoftwareKeyboard, CallbackResult}; /// use ctru::applets::swkbd::{SoftwareKeyboard, CallbackResult};
/// ///
/// let mut keyboard = SoftwareKeyboard::default(); /// let mut keyboard = SoftwareKeyboard::default();
/// ///
/// keyboard.set_filter_callback(Some(Box::new(|str| { /// keyboard.set_filter_callback(Some(Box::new(|str| {
/// if str.contains("boo") { /// if str.contains("boo") {
/// return ( /// return (CallbackResult::Retry, Some("Ah, you scared me!".into()));
/// CallbackResult::Retry,
/// Some(String::from("Ah, you scared me!")),
/// );
/// } /// }
/// ///
/// (CallbackResult::Ok, None) /// (CallbackResult::Ok, None)

Loading…
Cancel
Save