|
|
@ -1,5 +1,5 @@ |
|
|
|
//! Error handling interface.
|
|
|
|
//! Error handling interface.
|
|
|
|
//!
|
|
|
|
//!
|
|
|
|
//! This module holds the generic error and result types to interface with [`ctru_sys`] and the safe wrapper.
|
|
|
|
//! This module holds the generic error and result types to interface with [`ctru_sys`] and the safe wrapper.
|
|
|
|
use std::borrow::Cow; |
|
|
|
use std::borrow::Cow; |
|
|
|
use std::error; |
|
|
|
use std::error; |
|
|
@ -10,16 +10,16 @@ use std::ops::{ControlFlow, FromResidual, Try}; |
|
|
|
use ctru_sys::result::{R_DESCRIPTION, R_LEVEL, R_MODULE, R_SUMMARY}; |
|
|
|
use ctru_sys::result::{R_DESCRIPTION, R_LEVEL, R_MODULE, R_SUMMARY}; |
|
|
|
|
|
|
|
|
|
|
|
/// Custom type alias for generic `ctru` operations.
|
|
|
|
/// Custom type alias for generic `ctru` operations.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This type is compatible with `ctru-sys` result codes.
|
|
|
|
/// This type is compatible with `ctru-sys` result codes.
|
|
|
|
pub type Result<T> = ::std::result::Result<T, Error>; |
|
|
|
pub type Result<T> = ::std::result::Result<T, Error>; |
|
|
|
|
|
|
|
|
|
|
|
/// Validity checker of raw [`ctru_sys::Result`] codes.
|
|
|
|
/// Validity checker of raw [`ctru_sys::Result`] codes.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This struct supports the "try" syntax (`?`) to convert to an [`Error::Os`].
|
|
|
|
/// This struct supports the "try" syntax (`?`) to convert to an [`Error::Os`].
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
/// pub fn hid_init() -> crate::Result<()> {
|
|
|
|
/// pub fn hid_init() -> crate::Result<()> {
|
|
|
|
/// // We run an unsafe function which returns a `ctru_sys::Result`.
|
|
|
|
/// // We run an unsafe function which returns a `ctru_sys::Result`.
|
|
|
@ -71,13 +71,13 @@ impl<T> FromResidual<Error> for Result<T> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// The generic error enum returned by `ctru` functions.
|
|
|
|
/// The generic error enum returned by `ctru` functions.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This error enum supports parsing and displaying [`ctru_sys::Result`] codes.
|
|
|
|
/// This error enum supports parsing and displaying [`ctru_sys::Result`] codes.
|
|
|
|
#[non_exhaustive] |
|
|
|
#[non_exhaustive] |
|
|
|
pub enum Error { |
|
|
|
pub enum Error { |
|
|
|
/// Raw [`ctru_sys::Result`] codes.
|
|
|
|
/// Raw [`ctru_sys::Result`] codes.
|
|
|
|
Os(ctru_sys::Result), |
|
|
|
Os(ctru_sys::Result), |
|
|
|
/// Generic `libc` error codes.
|
|
|
|
/// Generic `libc` error codes.
|
|
|
|
Libc(String), |
|
|
|
Libc(String), |
|
|
|
/// Requested service is already active and cannot be activated again.
|
|
|
|
/// Requested service is already active and cannot be activated again.
|
|
|
|
ServiceAlreadyActive, |
|
|
|
ServiceAlreadyActive, |
|
|
@ -94,7 +94,7 @@ pub enum Error { |
|
|
|
|
|
|
|
|
|
|
|
impl Error { |
|
|
|
impl Error { |
|
|
|
/// Create an [`Error`] out of the last set value in `errno`.
|
|
|
|
/// Create an [`Error`] out of the last set value in `errno`.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This can be used to get a human-readable error string from calls to `libc` functions.
|
|
|
|
/// This can be used to get a human-readable error string from calls to `libc` functions.
|
|
|
|
pub(crate) fn from_errno() -> Self { |
|
|
|
pub(crate) fn from_errno() -> Self { |
|
|
|
let error_str = unsafe { |
|
|
|
let error_str = unsafe { |
|
|
|