From f2f64da50aad67cfe650045f96dc7f00417a1e1c Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Wed, 2 Feb 2022 22:47:06 -0500 Subject: [PATCH 1/2] Add basic Ps module which only has init() --- ctru-rs/src/services/mod.rs | 1 + ctru-rs/src/services/ps.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 ctru-rs/src/services/ps.rs diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 7a0e194..2159e9e 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -2,6 +2,7 @@ pub mod apt; pub mod fs; pub mod gspgpu; pub mod hid; +pub mod ps; pub mod soc; pub mod sslc; diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs new file mode 100644 index 0000000..a20e47e --- /dev/null +++ b/ctru-rs/src/services/ps.rs @@ -0,0 +1,21 @@ +#[non_exhaustive] +pub struct Ps; + +impl Ps { + pub fn init() -> crate::Result { + let r = unsafe { ctru_sys::psInit() }; + if r < 0 { + Err(r.into()) + } else { + Ok(Self) + } + } +} + +impl Drop for Ps { + fn drop(&mut self) { + unsafe { + ctru_sys::psExit(); + } + } +} From cb15f994866ea6bcbc5c8bf9e763422d2168b648 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Wed, 2 Feb 2022 23:04:07 -0500 Subject: [PATCH 2/2] Add docstring for PS module --- ctru-rs/src/services/ps.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs index a20e47e..5e9adfa 100644 --- a/ctru-rs/src/services/ps.rs +++ b/ctru-rs/src/services/ps.rs @@ -1,7 +1,15 @@ +//! Process Services (PS) module. This is used for miscellaneous utility tasks, but +//! is particularly important because it is used to generate random data, which +//! is required for common things like [`HashMap`](std::collections::HashMap). +//! See also + +/// PS handle. This must not be dropped in order for random generation +/// to work (in most cases, the lifetime of an application). #[non_exhaustive] pub struct Ps; impl Ps { + /// Initialize the PS module. pub fn init() -> crate::Result { let r = unsafe { ctru_sys::psInit() }; if r < 0 {