pub fn divide(left: usize, right: usize) -> Result<usize, MathError>Expand description
Divides the first argument over the second
§Errors
- Passing a zero as the right argument leds to a MathError::DivisionByZero error.
- Passing zero as both arguments results in a MathError::ZeroDividedByZero error.
§Examples
let result = daniels_basic_math::divide(2, 2);
assert!(matches!(result, Ok(1)));
let result = daniels_basic_math::divide(2, 0);
assert!(matches!(result, Err(daniels_basic_math::MathError::DivisionByZero)));
let result = daniels_basic_math::divide(0, 0);
assert!(matches!(result, Err(daniels_basic_math::MathError::ZeroDividedByZero)));