| 1 | use crate::RRuleError; |
| 2 | |
| 3 | pub(crate) fn checked_mul_u32(v1: u32, v2: u32, hint: Option<&str>) -> Result<u32, RRuleError> { |
| 4 | v1.checked_mul(v2).ok_or_else(|| match hint { |
| 5 | Some(hint) => RRuleError::new_iter_err(format!( |
| 6 | "Could not multiply number, would overflow (`{} * {}`), {}.", |
| 7 | v1, v2, hint |
| 8 | )), |
| 9 | None => RRuleError::new_iter_err(format!( |
| 10 | "Could not multiply number, would overflow (`{} * {}`).", |
| 11 | v1, v2, |
| 12 | )), |
| 13 | }) |
| 14 | } |
| 15 | |
| 16 | pub(crate) fn checked_add_u32(v1: u32, v2: u32, hint: Option<&str>) -> Result<u32, RRuleError> { |
| 17 | v1.checked_add(v2).ok_or_else(|| match hint { |
| 18 | Some(hint) => RRuleError::new_iter_err(format!( |
| 19 | "Could not add numbers, would overflow (`{} + {}`), {}.", |
| 20 | v1, v2, hint |
| 21 | )), |
| 22 | None => RRuleError::new_iter_err(format!( |
| 23 | "Could not add numbers, would overflow (`{} + {}`).", |
| 24 | v1, v2, |
| 25 | )), |
| 26 | }) |
| 27 | } |