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

Add ensure-ops family methods #12967

Merged
merged 43 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5684541
add ensure-ops family methods
lemunozm Dec 19, 2022
4d52919
fix cargo doc
lemunozm Dec 19, 2022
e6ac815
add EnsureOp and EnsureOpAssign meta traits
lemunozm Dec 19, 2022
9197649
move ensure module and ArithmeticError to sp-arithmetic
lemunozm Dec 20, 2022
61f2fc7
fix doc examples
lemunozm Dec 20, 2022
a3e9649
reexport ensure module content
lemunozm Dec 20, 2022
36feea6
ensure mod private
lemunozm Dec 20, 2022
43b8814
reexport to sp-runtime
lemunozm Dec 20, 2022
e4c1514
fix doc example
lemunozm Dec 20, 2022
0a2ee21
remove into(). in doc examples, minor doc changes
lemunozm Dec 20, 2022
f7b305c
remove return value from assign methods
lemunozm Dec 23, 2022
18857bc
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
df6e94f
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
240067b
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
95b386e
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
f9384d6
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
2a72a0d
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
8eaffcc
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
5870a3f
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
ac7bc37
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
274f4cd
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
8cd0460
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
4b4431c
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
c8c46fa
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
1e2471c
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
2b43271
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
ea54b66
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
e12cd9d
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
9b36839
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
5435fe4
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
cb0202e
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
d9fa4e1
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
3640a6f
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
5f59e68
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
0e6a2a6
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
d44e76c
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
784a803
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
48e68c5
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
2a2590b
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
b23f70f
Update primitives/arithmetic/src/traits.rs
lemunozm Dec 27, 2022
b0219f5
cargo fmt
lemunozm Dec 27, 2022
9ba9307
Apply suggestions from code review
bkchr Dec 28, 2022
048a34b
".git/.scripts/fmt.sh" 1
Dec 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions primitives/arithmetic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ pub use rational::{Rational128, RationalInfinite};
use sp_std::{cmp::Ordering, fmt::Debug, prelude::*};
use traits::{BaseArithmetic, One, SaturatedConversion, Unsigned, Zero};

use codec::{Decode, Encode};
use scale_info::TypeInfo;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

/// Arithmetic errors.
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum ArithmeticError {
/// Underflow.
Underflow,
/// Overflow.
Overflow,
/// Division by zero.
DivisionByZero,
}

impl From<ArithmeticError> for &'static str {
fn from(e: ArithmeticError) -> &'static str {
match e {
ArithmeticError::Underflow => "An underflow would occur",
ArithmeticError::Overflow => "An overflow would occur",
ArithmeticError::DivisionByZero => "Division by zero",
}
}
}

/// Trait for comparing two numbers with an threshold.
///
/// Returns:
Expand Down
Loading