Browse Source

implement suggestions + cleanup

pull/140/head
Lena 1 year ago committed by Lena
parent
commit
208abd1fbd
No known key found for this signature in database
GPG Key ID: 5A940B96C2DA3683
  1. 10
      ctru-rs/src/error.rs
  2. 12
      ctru-rs/src/services/ac.rs

10
ctru-rs/src/error.rs

@ -96,6 +96,8 @@ pub enum Error { @@ -96,6 +96,8 @@ pub enum Error {
},
/// An error that doesn't fit into the other categories.
Other(String),
/// UTF-8 buffer to [String] conversion error
Utf8(std::string::FromUtf8Error),
}
impl Error {
@ -137,6 +139,12 @@ impl From<ResultCode> for Error { @@ -137,6 +139,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 {
@ -157,6 +165,7 @@ impl fmt::Debug for Error { @@ -157,6 +165,7 @@ impl fmt::Debug for Error {
.field("wanted", wanted)
.finish(),
Self::Other(err) => f.debug_tuple("Other").field(err).finish(),
Self::Utf8(e) => f.debug_tuple("Utf8").field(e).finish(),
}
}
}
@ -181,6 +190,7 @@ impl fmt::Display for Error { @@ -181,6 +190,7 @@ impl fmt::Display for Error {
}
Self::BufferTooShort{provided, wanted} => write!(f, "the provided buffer's length is too short (length = {provided}) to hold the wanted data (size = {wanted})"),
Self::Other(err) => write!(f, "{err}"),
Self::Utf8(e) => write!(f, "UTF-8 conversion error: {e}")
}
}
}

12
ctru-rs/src/services/ac.rs

@ -1,7 +1,4 @@ @@ -1,7 +1,4 @@
use crate::error::ResultCode;
use std::ffi::CString;
use std::io::Write;
use std::marker::PhantomData;
pub struct Ac(());
impl Ac {
@ -43,7 +40,7 @@ impl Ac { @@ -43,7 +40,7 @@ impl Ac {
/// let ac = Ac::new()?;
///
/// println!("Waiting for an internet connection...");
/// ac.wait_for_internet_connection()?;
/// ac.wait_internet_connection()?;
/// println!("Connected.");
/// #
/// # Ok(())
@ -143,7 +140,7 @@ impl Ac { @@ -143,7 +140,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)?)
}
}
@ -234,7 +231,7 @@ impl Ac { @@ -234,7 +231,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)?)
}
}
@ -265,7 +262,7 @@ impl Ac { @@ -265,7 +262,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)?)
}
}
@ -308,6 +305,7 @@ impl Drop for Ac { @@ -308,6 +305,7 @@ impl Drop for Ac {
#[doc(alias = "acSecurityMode")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
#[non_exhaustive]
pub enum SecurityMode {
Open = 0,
WEP40Bit = 1,

Loading…
Cancel
Save