From 0d31a1970a2f33cd3b8d9d6df66bb5577eb1126d Mon Sep 17 00:00:00 2001 From: TechiePi Date: Sun, 9 Oct 2022 21:10:00 +0200 Subject: [PATCH] Remove unnecesary condition and explain the ``type Residual`` --- ctru-rs/src/error.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ctru-rs/src/error.rs b/ctru-rs/src/error.rs index 8d4eb1d..1acb855 100644 --- a/ctru-rs/src/error.rs +++ b/ctru-rs/src/error.rs @@ -13,6 +13,8 @@ pub(crate) struct LibCtruResult(pub i32); impl Try for LibCtruResult { type Output = (); + // This type is passed to [FromResidual::from_residual] when the LibCtruResult is an error, + // so this type implies "this is a result than CAN'T be `Ok`" (Infallible is the same as !) type Residual = crate::Result; fn from_output(_: Self::Output) -> Self { @@ -30,13 +32,9 @@ impl Try for LibCtruResult { impl FromResidual for LibCtruResult { fn from_residual(e: ::Residual) -> Self { - if let Some(e) = e.err() { - match e { - Error::Os(result) => Self(result), - _ => Self(-1), - } - } else { - Self(-1) + match e.err().unwrap() { + Error::Os(result) => Self(result), + _ => Self(-1), } } }