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

Commit

Permalink
add EnsureOp and EnsureOpAssign meta traits
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Dec 19, 2022
1 parent 4376583 commit 7de1c79
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,10 @@ pub mod ensure {
impl<T: CheckedMul + PartialOrd + Zero + Copy> EnsureMul for T {}
impl<T: CheckedDiv + PartialOrd + Zero + Copy> EnsureDiv for T {}

/// Meta trait that supports all arithmetic operations
pub trait EnsureOp: EnsureAdd + EnsureSub + EnsureMul + EnsureDiv {}
impl<T: EnsureAdd + EnsureSub + EnsureMul + EnsureDiv> EnsureOp for T {}

/// Performs self addition that returns `ArithmeticError` instead of wrapping around on
/// overflow.
pub trait EnsureAddAssign: EnsureAdd {
Expand Down Expand Up @@ -2203,6 +2207,10 @@ pub mod ensure {
impl<T: EnsureMul> EnsureMulAssign for T {}
impl<T: EnsureDiv> EnsureDivAssign for T {}

/// Meta trait that supports all assigned arithmetic operations
pub trait EnsureOpAssign: EnsureAdd + EnsureSub + EnsureMul + EnsureDiv {}
impl<T: EnsureAdd + EnsureSub + EnsureMul + EnsureDiv> EnsureOpAssign for T {}

/// Extends `FixedPointNumber with` the Ensure family functions.
pub trait EnsureFixedPointNumber: FixedPointNumber {
/// Creates `self` from a rational number. Equal to `n / d`.
Expand Down

0 comments on commit 7de1c79

Please sign in to comment.