From 341091f64788da1a06b23f013cff91df6a27ee58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Violeta=20Hern=C3=A1ndez?= Date: Sat, 10 Apr 2021 00:12:26 -0500 Subject: [PATCH] `pow_mut` now returns `Result`. --- src/linalg/pow.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/linalg/pow.rs b/src/linalg/pow.rs index 4b73784b..edcf55dd 100644 --- a/src/linalg/pow.rs +++ b/src/linalg/pow.rs @@ -14,22 +14,23 @@ where { /// Attempts to raise this matrix to an integral power `e` in-place. If this /// matrix is non-invertible and `e` is negative, it leaves this matrix - /// untouched and returns `false`. Otherwise, it returns `true` and + /// untouched and returns `Err(())`. Otherwise, it returns `Ok(())` and /// overwrites this matrix with the result. - pub fn pow_mut(&mut self, mut e: T) -> bool { + #[must_use] + pub fn pow_mut(&mut self, mut e: T) -> Result<(), ()> { let zero = T::zero(); // A matrix raised to the zeroth power is just the identity. if e == zero { self.fill_with_identity(); - return true; + return Ok(()); } // If e is negative, we compute the inverse matrix, then raise it to the // power of -e. if e < zero { if !self.try_inverse_mut() { - return false; + return Err(()); } } @@ -52,7 +53,7 @@ where multiplier.copy_from(&buf); if e == zero { - return true; + return Ok(()); } } } @@ -63,10 +64,9 @@ where pub fn pow(&self, e: T) -> Option { let mut clone = self.clone(); - if clone.pow_mut(e) { - Some(clone) - } else { - None + match clone.pow_mut(e) { + Ok(()) => Some(clone), + Err(()) => None, } } }