Browse Source

Re-introduced RAII semeantics for {Apt, Hid, Sdmc}

pull/10/head
Fenrir 9 years ago
parent
commit
6f84a43cab
  1. 2
      src/sdmc.rs
  2. 20
      src/services/apt.rs
  3. 19
      src/services/hid.rs

2
src/sdmc.rs

@ -7,7 +7,7 @@ pub struct Sdmc { @@ -7,7 +7,7 @@ pub struct Sdmc {
}
impl Sdmc {
pub fn new() -> Result<Self, i32> {
pub fn new() -> Result<Sdmc, i32> {
unsafe {
let r = sdmcInit();
if r < 0 {

20
src/services/apt.rs

@ -51,13 +51,21 @@ impl From<apt::APT_AppStatus> for AppStatus { @@ -51,13 +51,21 @@ impl From<apt::APT_AppStatus> for AppStatus {
}
pub struct Apt {
pd: PhantomData<()>,
pd: PhantomData<i32>
}
impl Apt {
pub fn new() -> Apt {
Apt { pd: PhantomData }
pub fn new() -> Result<Apt, i32> {
unsafe {
let r = apt::aptInit();
if r < 0 {
Err(r)
} else {
Ok(Apt { pd: PhantomData })
}
}
}
pub fn get_status(&self) -> AppStatus {
unsafe { apt::aptGetStatus().into() }
@ -88,3 +96,9 @@ impl Apt { @@ -88,3 +96,9 @@ impl Apt {
}
}
}
impl Drop for Apt {
fn drop(&mut self) {
unsafe { apt::aptExit() };
}
}

19
src/services/hid.rs

@ -74,12 +74,19 @@ impl From<PadKey> for u32 { @@ -74,12 +74,19 @@ impl From<PadKey> for u32 {
}
pub struct Hid {
pd: PhantomData<()>,
pd: PhantomData<i32>
}
impl Hid {
pub fn new() -> Hid {
Hid { pd: PhantomData }
pub fn new() -> Result<Hid, i32> {
unsafe {
let r = hid::hidInit();
if r < 0 {
Err(r)
} else {
Ok(Hid { pd: PhantomData })
}
}
}
pub fn scan_input(&mut self) {
@ -119,3 +126,9 @@ impl Hid { @@ -119,3 +126,9 @@ impl Hid {
}
}
}
impl Drop for Hid {
fn drop(&mut self) {
unsafe { hid::hidExit() };
}
}

Loading…
Cancel
Save