Browse Source

Cargo fmt

pull/78/head
TechiePi 2 years ago
parent
commit
de51d97d1c
  1. 87
      ctru-rs/src/applets/mii_selector.rs
  2. 2
      ctru-rs/src/applets/mod.rs

87
ctru-rs/src/applets/mii_selector.rs

@ -1,5 +1,5 @@
use std::ffi::{CString};
use bitflags::bitflags; use bitflags::bitflags;
use std::ffi::CString;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum MiiConfigIndex { pub enum MiiConfigIndex {
@ -9,10 +9,7 @@ pub enum MiiConfigIndex {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum MiiType { pub enum MiiType {
Guest { Guest { index: u32, name: String },
index: u32,
name: String,
},
User, User,
} }
@ -39,7 +36,9 @@ pub struct MiiSelectorReturn {
impl MiiSelector { impl MiiSelector {
pub fn init() -> Self { pub fn init() -> Self {
let mut config = Box::<ctru_sys::MiiSelectorConf>::default(); let mut config = Box::<ctru_sys::MiiSelectorConf>::default();
unsafe { ctru_sys::miiSelectorInit(config.as_mut()); } unsafe {
ctru_sys::miiSelectorInit(config.as_mut());
}
Self { config } Self { config }
} }
@ -47,7 +46,9 @@ impl MiiSelector {
// This can only fail if the text contains NUL bytes in the string... which seems // This can only fail if the text contains NUL bytes in the string... which seems
// unlikely and is documented // unlikely and is documented
let c_text = CString::new(text).expect("Cstring::new failed"); let c_text = CString::new(text).expect("Cstring::new failed");
unsafe { ctru_sys::miiSelectorSetTitle(self.config.as_mut(), c_text.as_ptr()); } unsafe {
ctru_sys::miiSelectorSetTitle(self.config.as_mut(), c_text.as_ptr());
}
} }
pub fn set_options(&mut self, options: Options) { pub fn set_options(&mut self, options: Options) {
@ -56,45 +57,57 @@ impl MiiSelector {
pub fn whitelist_guest_mii(&mut self, mii_index: MiiConfigIndex) { pub fn whitelist_guest_mii(&mut self, mii_index: MiiConfigIndex) {
match mii_index { match mii_index {
MiiConfigIndex::Index(i) => { MiiConfigIndex::Index(i) => unsafe {
unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), i) } ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), i)
} },
MiiConfigIndex::All => { MiiConfigIndex::All => unsafe {
unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), ctru_sys::MIISELECTOR_GUESTMII_SLOTS) } ctru_sys::miiSelectorWhitelistGuestMii(
} self.config.as_mut(),
ctru_sys::MIISELECTOR_GUESTMII_SLOTS,
)
},
} }
} }
pub fn blacklist_guest_mii(&mut self, mii_index: MiiConfigIndex) { pub fn blacklist_guest_mii(&mut self, mii_index: MiiConfigIndex) {
match mii_index { match mii_index {
MiiConfigIndex::Index(i) => { MiiConfigIndex::Index(i) => unsafe {
unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), i) } ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), i)
} },
MiiConfigIndex::All => { MiiConfigIndex::All => unsafe {
unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), ctru_sys::MIISELECTOR_GUESTMII_SLOTS) } ctru_sys::miiSelectorBlacklistGuestMii(
} self.config.as_mut(),
ctru_sys::MIISELECTOR_GUESTMII_SLOTS,
)
},
} }
} }
pub fn whitelist_user_mii(&mut self, mii_index: MiiConfigIndex) { pub fn whitelist_user_mii(&mut self, mii_index: MiiConfigIndex) {
match mii_index { match mii_index {
MiiConfigIndex::Index(i) => { MiiConfigIndex::Index(i) => unsafe {
unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), i) } ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), i)
} },
MiiConfigIndex::All => { MiiConfigIndex::All => unsafe {
unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), ctru_sys::MIISELECTOR_USERMII_SLOTS) } ctru_sys::miiSelectorWhitelistUserMii(
} self.config.as_mut(),
ctru_sys::MIISELECTOR_USERMII_SLOTS,
)
},
} }
} }
pub fn blacklist_user_mii(&mut self, mii_index: MiiConfigIndex) { pub fn blacklist_user_mii(&mut self, mii_index: MiiConfigIndex) {
match mii_index { match mii_index {
MiiConfigIndex::Index(i) => { MiiConfigIndex::Index(i) => unsafe {
unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), i) } ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), i)
} },
MiiConfigIndex::All => { MiiConfigIndex::All => unsafe {
unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), ctru_sys::MIISELECTOR_USERMII_SLOTS) } ctru_sys::miiSelectorBlacklistUserMii(
} self.config.as_mut(),
ctru_sys::MIISELECTOR_USERMII_SLOTS,
)
},
} }
} }
@ -106,9 +119,7 @@ impl MiiSelector {
pub fn launch(&mut self) -> MiiSelectorReturn { pub fn launch(&mut self) -> MiiSelectorReturn {
let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default(); let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default();
unsafe { unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) }
ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut())
}
return_val.into() return_val.into()
} }
@ -117,7 +128,9 @@ impl MiiSelector {
impl MiiSelectorReturn { impl MiiSelectorReturn {
pub fn name(&self) -> String { pub fn name(&self) -> String {
let mut tmp = [0u8; 36]; let mut tmp = [0u8; 36];
unsafe { ctru_sys::miiSelectorReturnGetName(self.raw_return.as_ref(), tmp.as_mut_ptr(), 36) } unsafe {
ctru_sys::miiSelectorReturnGetName(self.raw_return.as_ref(), tmp.as_mut_ptr(), 36)
}
let len = unsafe { libc::strlen(tmp.as_ptr()) }; let len = unsafe { libc::strlen(tmp.as_ptr()) };
let utf8 = unsafe { std::str::from_utf8_unchecked(&tmp[..len]) }; let utf8 = unsafe { std::str::from_utf8_unchecked(&tmp[..len]) };
@ -127,7 +140,9 @@ impl MiiSelectorReturn {
pub fn author(&self) -> String { pub fn author(&self) -> String {
let mut tmp = [0u8; 30]; let mut tmp = [0u8; 30];
unsafe { ctru_sys::miiSelectorReturnGetAuthor(self.raw_return.as_ref(), tmp.as_mut_ptr(), 30) } unsafe {
ctru_sys::miiSelectorReturnGetAuthor(self.raw_return.as_ref(), tmp.as_mut_ptr(), 30)
}
let len = unsafe { libc::strlen(tmp.as_ptr()) }; let len = unsafe { libc::strlen(tmp.as_ptr()) };
let utf8 = unsafe { std::str::from_utf8_unchecked(&tmp[..len]) }; let utf8 = unsafe { std::str::from_utf8_unchecked(&tmp[..len]) };

2
ctru-rs/src/applets/mod.rs

@ -1,2 +1,2 @@
pub mod swkbd;
pub mod mii_selector; pub mod mii_selector;
pub mod swkbd;

Loading…
Cancel
Save