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