Skip to content

Commit 2f7e74d

Browse files
committed
Add MathOp helper methods
It's helpful to be able to assert what type of Math error occurred.
1 parent 41f26cf commit 2f7e74d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

units/src/result.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ impl MathOp {
254254

255255
/// Returns `true` if this operation error'ed due to division by zero.
256256
pub fn is_div_by_zero(self) -> bool { !self.is_overflow() }
257+
258+
/// Returns `true` if this operation error'ed due to addition.
259+
pub fn is_addition(self) -> bool { self == MathOp::Add }
260+
261+
/// Returns `true` if this operation error'ed due to subtraction.
262+
pub fn is_subtraction(self) -> bool { self == MathOp::Sub }
263+
264+
/// Returns `true` if this operation error'ed due to multiplication.
265+
pub fn is_multiplication(self) -> bool { self == MathOp::Mul }
266+
267+
/// Returns `true` if this operation error'ed due to negation.
268+
pub fn is_negation(self) -> bool { self == MathOp::Neg }
257269
}
258270

259271
impl fmt::Display for MathOp {

0 commit comments

Comments
 (0)