Skip to content

Commit

Permalink
implement suggestions + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adryzz committed Oct 30, 2023
1 parent 586dfc1 commit e9f29af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 0 additions & 2 deletions ctru-rs/examples/wifi-info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Wi-Fi info example
//!
//! This example prints out all the info about the console's network, like SSID, security, proxy info...
//!
//! ```
use ctru::{prelude::*, services::ac::Ac};

Expand Down
11 changes: 10 additions & 1 deletion ctru-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub enum Error {
/// Size of the requested data (in bytes).
wanted: usize,
},
Utf8(std::string::FromUtf8Error),

Check warning on line 97 in ctru-rs/src/error.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2023-06-01)

missing documentation for a variant
}

impl Error {
Expand Down Expand Up @@ -127,6 +128,12 @@ impl From<ResultCode> for Error {
}
}

impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Self {
Error::Utf8(err)
}
}

impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand All @@ -146,6 +153,7 @@ impl fmt::Debug for Error {
.field("provided", provided)
.field("wanted", wanted)
.finish(),
Self::Utf8(e) => f.debug_tuple("Utf8").field(e).finish(),
}
}
}
Expand All @@ -168,7 +176,8 @@ impl fmt::Display for Error {
Self::OutputAlreadyRedirected => {
write!(f, "output streams are already redirected to 3dslink")
}
Self::BufferTooShort{provided, wanted} => write!(f, "the provided buffer's length is too short (length = {provided}) to hold the wanted data (size = {wanted})")
Self::BufferTooShort{provided, wanted} => write!(f, "the provided buffer's length is too short (length = {provided}) to hold the wanted data (size = {wanted})"),
Self::Utf8(e) => write!(f, "UTF-8 conversion error: {e}")
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions ctru-rs/src/services/ac.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::error::ResultCode;
use crate::services::fs::FsMediaType;
use std::ffi::CString;
use std::io::Write;
use std::marker::PhantomData;

pub struct Ac(());

Check warning on line 3 in ctru-rs/src/services/ac.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2023-06-01)

missing documentation for a struct

impl Ac {
Expand Down Expand Up @@ -144,7 +141,7 @@ impl Ac {
let mut vec = vec![0u8; len as usize];
ResultCode(ctru_sys::ACU_GetSSID(vec.as_mut_ptr()))?;
// how do i handle this error?
Ok(String::from_utf8(vec).unwrap())
Ok(String::from_utf8(vec)?)
}
}

Expand Down Expand Up @@ -235,7 +232,7 @@ impl Ac {
ResultCode(ctru_sys::ACU_GetProxyUserName(vec.as_mut_ptr()))?;

// how do i handle this error?
Ok(String::from_utf8(vec).unwrap())
Ok(String::from_utf8(vec)?)
}
}

Expand Down Expand Up @@ -266,7 +263,7 @@ impl Ac {
ResultCode(ctru_sys::ACU_GetProxyPassword(vec.as_mut_ptr()))?;

// how do i handle this error?
Ok(String::from_utf8(vec).unwrap())
Ok(String::from_utf8(vec)?)
}
}

Expand Down Expand Up @@ -309,6 +306,7 @@ impl Drop for Ac {
#[doc(alias = "acSecurityMode")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
#[non_exhaustive]
pub enum SecurityMode {

Check warning on line 310 in ctru-rs/src/services/ac.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2023-06-01)

missing documentation for an enum
Open = 0,

Check warning on line 311 in ctru-rs/src/services/ac.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2023-06-01)

missing documentation for a variant
WEP40Bit = 1,

Check warning on line 312 in ctru-rs/src/services/ac.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2023-06-01)

missing documentation for a variant
Expand Down

0 comments on commit e9f29af

Please sign in to comment.