mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Bound Unsigned when signed is not supported. (#6367)
* bound unsigned when necessary * convert more type to AtLeast32BitUnsigned * Update primitives/arithmetic/src/traits.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * doc refactor * line reorganize Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b17ccf24a8
commit
44fb311f1f
@@ -17,7 +17,7 @@
|
||||
|
||||
//! Provides some utilities to define a piecewise linear function.
|
||||
|
||||
use crate::{Perbill, traits::{AtLeast32Bit, SaturatedConversion}};
|
||||
use crate::{Perbill, traits::{AtLeast32BitUnsigned, SaturatedConversion}};
|
||||
use core::ops::Sub;
|
||||
|
||||
/// Piecewise Linear function in [0, 1] -> [0, 1].
|
||||
@@ -36,7 +36,7 @@ fn abs_sub<N: Ord + Sub<Output=N> + Clone>(a: N, b: N) -> N where {
|
||||
impl<'a> PiecewiseLinear<'a> {
|
||||
/// Compute `f(n/d)*d` with `n <= d`. This is useful to avoid loss of precision.
|
||||
pub fn calculate_for_fraction_times_denominator<N>(&self, n: N, d: N) -> N where
|
||||
N: AtLeast32Bit + Clone
|
||||
N: AtLeast32BitUnsigned + Clone
|
||||
{
|
||||
let n = n.min(d.clone());
|
||||
|
||||
@@ -80,7 +80,7 @@ impl<'a> PiecewiseLinear<'a> {
|
||||
// This is guaranteed not to overflow on whatever values nor lose precision.
|
||||
// `q` must be superior to zero.
|
||||
fn multiply_by_rational_saturating<N>(value: N, p: u32, q: u32) -> N
|
||||
where N: AtLeast32Bit + Clone
|
||||
where N: AtLeast32BitUnsigned + Clone
|
||||
{
|
||||
let q = q.max(1);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef, Error};
|
||||
use crate::traits::{
|
||||
self, Member, AtLeast32Bit, SimpleBitOps, Hash as HashT,
|
||||
self, Member, AtLeast32BitUnsigned, SimpleBitOps, Hash as HashT,
|
||||
MaybeSerializeDeserialize, MaybeSerialize, MaybeDisplay,
|
||||
MaybeMallocSizeOf,
|
||||
};
|
||||
@@ -123,7 +123,7 @@ impl<Number, Hash> codec::EncodeLike for Header<Number, Hash> where
|
||||
|
||||
impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
Number: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash + MaybeDisplay +
|
||||
AtLeast32Bit + Codec + Copy + Into<U256> + TryFrom<U256> + sp_std::str::FromStr +
|
||||
AtLeast32BitUnsigned + Codec + Copy + Into<U256> + TryFrom<U256> + sp_std::str::FromStr +
|
||||
MaybeMallocSizeOf,
|
||||
Hash: HashT,
|
||||
Hash::Output: Default + sp_std::hash::Hash + Copy + Member + Ord +
|
||||
@@ -171,7 +171,8 @@ impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
}
|
||||
|
||||
impl<Number, Hash> Header<Number, Hash> where
|
||||
Number: Member + sp_std::hash::Hash + Copy + MaybeDisplay + AtLeast32Bit + Codec + Into<U256> + TryFrom<U256>,
|
||||
Number: Member + sp_std::hash::Hash + Copy + MaybeDisplay + AtLeast32BitUnsigned + Codec +
|
||||
Into<U256> + TryFrom<U256>,
|
||||
Hash: HashT,
|
||||
Hash::Output: Default + sp_std::hash::Hash + Copy + Member + MaybeDisplay + SimpleBitOps + Codec,
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
//! ```
|
||||
|
||||
use crate::offchain::storage::StorageValueRef;
|
||||
use crate::traits::AtLeast32Bit;
|
||||
use crate::traits::AtLeast32BitUnsigned;
|
||||
use codec::{Codec, Decode, Encode};
|
||||
use sp_core::offchain::{Duration, Timestamp};
|
||||
use sp_io::offchain;
|
||||
@@ -430,7 +430,7 @@ where
|
||||
/// used with [`BlockAndTime<BlockNumberProvider>`](BlockAndTime).
|
||||
pub trait BlockNumberProvider {
|
||||
/// Type of `BlockNumber` to provide.
|
||||
type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32Bit;
|
||||
type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32BitUnsigned;
|
||||
/// Returns the current block number.
|
||||
///
|
||||
/// Provides an abstraction over an arbitrary way of providing the
|
||||
|
||||
@@ -34,8 +34,8 @@ use crate::transaction_validity::{
|
||||
};
|
||||
use crate::generic::{Digest, DigestItem};
|
||||
pub use sp_arithmetic::traits::{
|
||||
AtLeast32Bit, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating, SaturatedConversion,
|
||||
Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv,
|
||||
AtLeast32Bit, AtLeast32BitUnsigned, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating,
|
||||
SaturatedConversion, Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv,
|
||||
CheckedShl, CheckedShr, IntegerSquareRoot
|
||||
};
|
||||
use sp_application_crypto::AppKey;
|
||||
@@ -490,9 +490,8 @@ pub trait Header:
|
||||
MaybeMallocSizeOf + 'static
|
||||
{
|
||||
/// Header number.
|
||||
type Number: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash
|
||||
+ Copy + MaybeDisplay + AtLeast32Bit + Codec + sp_std::str::FromStr
|
||||
+ MaybeMallocSizeOf;
|
||||
type Number: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash + Copy +
|
||||
MaybeDisplay + AtLeast32BitUnsigned + Codec + sp_std::str::FromStr + MaybeMallocSizeOf;
|
||||
/// Header hash type
|
||||
type Hash: Member + MaybeSerializeDeserialize + Debug + sp_std::hash::Hash + Ord
|
||||
+ Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]>
|
||||
|
||||
Reference in New Issue
Block a user