mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Scale trait and move to u32 blocknumbers (#3357)
* Scale trait and move to u32 blocknumbers. * Fixes * Cleanups * Update node/runtime/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Fix up some of the factory stuff. * Update core/sr-primitives/src/traits.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Move Nonce/Index to u32 (#3361) * Force a non-borked version of upstream crate * Line lengths and runtime version bump
This commit is contained in:
@@ -303,6 +303,47 @@ pub trait CheckedConversion {
|
||||
}
|
||||
impl<T: Sized> CheckedConversion for T {}
|
||||
|
||||
/// Multiply and divide by a number that isn't necessarily the same type. Basically just the same
|
||||
/// as `Mul` and `Div` except it can be used for all basic numeric types.
|
||||
pub trait Scale<Other> {
|
||||
/// The output type of the product of `self` and `Other`.
|
||||
type Output;
|
||||
|
||||
/// @return the product of `self` and `other`.
|
||||
fn mul(self, other: Other) -> Self::Output;
|
||||
|
||||
/// @return the integer division of `self` and `other`.
|
||||
fn div(self, other: Other) -> Self::Output;
|
||||
|
||||
/// @return the modulo remainder of `self` and `other`.
|
||||
fn rem(self, other: Other) -> Self::Output;
|
||||
}
|
||||
macro_rules! impl_scale {
|
||||
($self:ty, $other:ty) => {
|
||||
impl Scale<$other> for $self {
|
||||
type Output = Self;
|
||||
fn mul(self, other: $other) -> Self::Output { self * (other as Self) }
|
||||
fn div(self, other: $other) -> Self::Output { self / (other as Self) }
|
||||
fn rem(self, other: $other) -> Self::Output { self % (other as Self) }
|
||||
}
|
||||
}
|
||||
}
|
||||
impl_scale!(u128, u128);
|
||||
impl_scale!(u128, u64);
|
||||
impl_scale!(u128, u32);
|
||||
impl_scale!(u128, u16);
|
||||
impl_scale!(u128, u8);
|
||||
impl_scale!(u64, u64);
|
||||
impl_scale!(u64, u32);
|
||||
impl_scale!(u64, u16);
|
||||
impl_scale!(u64, u8);
|
||||
impl_scale!(u32, u32);
|
||||
impl_scale!(u32, u16);
|
||||
impl_scale!(u32, u8);
|
||||
impl_scale!(u16, u16);
|
||||
impl_scale!(u16, u8);
|
||||
impl_scale!(u8, u8);
|
||||
|
||||
/// Trait for things that can be clear (have no bits set). For numeric types, essentially the same
|
||||
/// as `Zero`.
|
||||
pub trait Clear {
|
||||
|
||||
Reference in New Issue
Block a user