Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 2bc3f02

Browse files
committed
move ensure module and ArithmeticError to sp-arithmetic
1 parent 404cfdf commit 2bc3f02

File tree

4 files changed

+544
-541
lines changed

4 files changed

+544
-541
lines changed

primitives/arithmetic/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ pub use rational::{Rational128, RationalInfinite};
5050
use sp_std::{cmp::Ordering, fmt::Debug, prelude::*};
5151
use traits::{BaseArithmetic, One, SaturatedConversion, Unsigned, Zero};
5252

53+
use codec::{Decode, Encode};
54+
use scale_info::TypeInfo;
55+
56+
#[cfg(feature = "std")]
57+
use serde::{Deserialize, Serialize};
58+
59+
/// Arithmetic errors.
60+
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug, TypeInfo)]
61+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
62+
pub enum ArithmeticError {
63+
/// Underflow.
64+
Underflow,
65+
/// Overflow.
66+
Overflow,
67+
/// Division by zero.
68+
DivisionByZero,
69+
}
70+
71+
impl From<ArithmeticError> for &'static str {
72+
fn from(e: ArithmeticError) -> &'static str {
73+
match e {
74+
ArithmeticError::Underflow => "An underflow would occur",
75+
ArithmeticError::Overflow => "An overflow would occur",
76+
ArithmeticError::DivisionByZero => "Division by zero",
77+
}
78+
}
79+
}
80+
5381
/// Trait for comparing two numbers with an threshold.
5482
///
5583
/// Returns:

0 commit comments

Comments
 (0)