mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Add ensure-ops family methods (#12967)
* add ensure-ops family methods * fix cargo doc * add EnsureOp and EnsureOpAssign meta traits * move ensure module and ArithmeticError to sp-arithmetic * fix doc examples * reexport ensure module content * ensure mod private * reexport to sp-runtime * fix doc example * remove into(). in doc examples, minor doc changes * remove return value from assign methods * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/arithmetic/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * cargo fmt * Apply suggestions from code review * ".git/.scripts/fmt.sh" 1 Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
0a94112c9d
commit
af79220695
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user