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

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

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

Loading…
Cancel
Save